python - 如何在 TensorFlow 中计算张量的加权和?

标签 python tensorflow

我想计算张量每一行的加权和,权重是元素,另一个乘数是列号。示例失败:

input:
[[0.2 0.5 0.3],
 [0.4 0.1 0.5]]

output:
[0.2*0+0.5*1+0.3*2, 0.4*0+0.1*1+0.5*2] = [1.1, 1.1]

我该如何处理它?<​​/p>

最佳答案

这就是内积的定义。与numpy.dot :

data=[[0.2, 0.5, 0.3], [0.4, 0.1, 0.5]]
np.dot(data,range(len(data)+1))
array([ 1.1,  1.1])

关于python - 如何在 TensorFlow 中计算张量的加权和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48659449/

相关文章:

python - 为什么 Django 的 RelatedManager 不在目标对象上缓存调用查找的对象?

python - 为什么用 python 编写的决策树代码的预测结果与用 R 编写的代码不同?

python - 使用 numpy 进行 3D 图像压缩

python - Keras 模型重复输出 0,没有错误

python-3.x - 使用 Keras 和 TensorFlow 后端可重现结果

python - KalmanFilter 总是在第一时间预测 0,0

python - 替换 numpy 条目的省时方法

python - MFCC Python : completely different result from librosa vs python_speech_features vs tensorflow. 信号

python - Tensorflow安装错误: No module named _pywarp_tensorflow

python - TensorFlow 对象检测 API 评估训练性能