import numpy as np
import tensorflow as tf
a = tf.constant(np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]]),dtype=tf.float32)
b = tf.reduce_sum(a,axis=0)
c = tf.reduce_sum(a,axis=1)
sess = tf.Session()
print(a.get_shape())
print(sess.run(b))
print(sess.run©)
运行结果:
(3, 4)
[ 3. 6. 9. 12.] ------->第一维相加
[10. 10. 10.] ------->第二维相加