TensorFlow:Hadamard产品::我如何得到这个?

don*_*lan 8 python tensorflow

Tensorflow具有以下功能:

tf.matmul
Run Code Online (Sandbox Code Playgroud)

它将两个向量相乘并产生一个标量.

但是,我需要做以下事情:

# 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)
Run Code Online (Sandbox Code Playgroud)

但是,为了通过矩阵乘法实现这一点,我无法设置softmax_weight_variable.我需要使用"Tensor Product"(也称为"Outer Product"......),但这个功能似乎没有实现.

如何在TensorFlow中实现Hadamard(元素方式)乘法和外积?

use*_*ica 8

元素乘法xy只是tf.mul(x, y).这也支持NumPy风格的广播,如果需要,您应该可以使用它来获得外部产品.