一个很好的介绍的博客:彻底理解 tf.reduce_sum() - 简书 (jianshu.com)
代码举例:
sess = tf.Session()
tensor = [[[ 1 , 2 , 3 , 4],
[ 5 , 6, 7 , 8],
[ 9 , 10, 11, 12]],
[[ 13, 14 ,15 ,16],
[ 17 , 18 ,19, 20],
[ 21, 22 ,23 ,24]]]
import numpy as np
c= tf.reduce_sum(tensor, axis=-1)
print( sess.run(c))
结果:
[[10 26 42]
[58 74 90]]