python - TensorFlow:Hadamard 产品::我如何获得它?

标签 python tensorflow

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(按元素)乘法和外积?

最佳答案

xy 的逐元素乘法就是tf.mul(x, y) .这也是supports NumPy-style broadcasting ,如果需要,您应该可以使用它来获得外部产品。

关于python - TensorFlow:Hadamard 产品::我如何获得它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36875498/

相关文章:

Python 对文本文件进行排序?

Python 排序字典 : Key [Ascending] and then Value [Descending]

python - 我可以将 DateTimeFields 与标签 "if"进行比较吗?

python - Keras 中的多个输出

python - 如何从张量中提取子矩阵?

python os.listdir() 显示 protected 文件

python - 什么是 pandas dataframe.ne 方法以及为什么使用它?

c++ - 添加op tensorflow调试

python-3.x - 如何解决 "logits and labels must have the same first dimension"错误

python - 将元数据添加到 Keras LSTM