python reduce_sum使用记录

import tensorflow as tf
data=[[1,1,2],[1,1,1]]

#行列求和
defaultReduceSume=tf.reduce_sum(data)
#行列求和
hangLieReduceSumBy=tf.reduce_sum(data, [0, 1])


#按行求和
hangReduceSum=tf.reduce_sum(data,1)
#按列求和
lieReduceSum=tf.reduce_sum(data,0)

#默认是按行排列 ,true是按列排列
hangZReduceSum=tf.reduce_sum(data, 1, keep_dims=True)



with tf.Session() as sess:
    print(sess.run(defaultReduceSume))
    print(sess.run(hangLieReduceSumBy))
    print(sess.run(hangReduceSum))
    print(sess.run(lieReduceSum))
    print(sess.run(hangZReduceSum))

打印结果:
7
7
[4 3]
[2 2 3]
[[4]
[3]]

你可能感兴趣的:(python reduce_sum使用记录)