Tensorflow数学运算减少\u和

Tensorflow数学运算减少\u和,tensorflow,Tensorflow,结果是: import tensorflow as tf a = tf.constant([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]]) b = tf.constant([[5,4,3,2,1],[1,2,3,4,5],[1,2,3,4,5]]) product =tf.mul(a,b) product_sum =tf.reduce_sum(tf.mul(a,b)) with tf.Session() as sess: print product.eva

结果是:

import tensorflow as tf
a = tf.constant([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]])
b = tf.constant([[5,4,3,2,1],[1,2,3,4,5],[1,2,3,4,5]])

product =tf.mul(a,b)
product_sum =tf.reduce_sum(tf.mul(a,b))

with tf.Session() as sess:
    print product.eval()
    print product_sum.eval()
但这不是我想要的答案

我想得到答案

[5+8+9+8+5,1+4+9+16+25,1+4+9+16+25] =[35,55,55]

正如中提到的xxi,这里正确的解决方案是在调用时使用可选的
参数。在本例中,您希望沿柱轴减小,因此以下代码将起作用:

[[ 5  8  9  8  5]

[ 1  4  9 16 25]

[ 1  4  9 16 25]]

145

(还要注意,在TensorFlow 1.0中,
tf.mul()
现在是。)

product\u sum=tf.reduce\u sum(product,axis=1)
是的,你是对的,这太棒了!!非常感谢。
product = tf.multiply(a, b)
product_sum = tf.reduce_sum(product, axis=1)