我找不到记录 *
的位置。它似乎可以等效于 tf.multiply
或 tf.scalar_mul
。是这样吗?
最佳答案
最可靠的文档是 source code :
def _mul_dispatch(x, y, name=None):
"""Dispatches cwise mul for "Dense*Dense" and "Dense*Sparse"."""
is_tensor_y = isinstance(y, ops.Tensor)
if is_tensor_y:
return gen_math_ops._mul(x, y, name=name)
else:
assert isinstance(y, sparse_tensor.SparseTensor) # Case: Dense * Sparse.
new_vals = gen_sparse_ops.sparse_dense_cwise_mul(y.indices, y.values,
y.dense_shape, x, name)
return sparse_tensor.SparseTensor(y.indices, new_vals, y.dense_shape)
...
_OverrideBinaryOperatorHelper(_mul_dispatch, "mul")
这意味着 __mul__
运算符重载,它执行 _mul_dispatch
。如您所见,如果张量是稀疏的,它会调用 gen_math_ops._mul
(这是 tf.multiply
的底层核心函数)或 sparse_dense_cwise_mul
。
顺便说一句,tf.scalar_mul
只是 scalar * x
( source code ) 的包装器,所以它基本上是同一件事,但依赖关系是反过来。
关于python - tensorflow 中 `*` 记录在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47746646/