Tensorflow 具有以下功能:
tf.matmul
将两个向量相乘并产生一个标量。
但是,我需要做以下事情:
# dense dim: (?,227)
dense_part = tf.nn.relu(some stuff here)
# softmax matrix dim: (?,227,19) or (?,19,227) or (?,227,227), where I
# ....can slice the last dim down to (?,227,19)
softmax_matrix = tf.matmul(dense_part,softmax_weight_variable)
但是,为了通过矩阵乘法完成此操作,我无法设置 softmax_weight_variable。我需要使用“Tensor Product”(也称为“Outer Product”...)但是这个功能似乎没有实现。
如何在 TensorFlow 中实现 Hadamard(按元素)乘法和外积?
最佳答案
x
和y
的逐元素乘法就是tf.mul(x, y)
.这也是supports NumPy-style broadcasting ,如果需要,您应该可以使用它来获得外部产品。
关于python - TensorFlow:Hadamard 产品::我如何获得它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36875498/