美文网首页
tensorflow的reduce_sum()方法

tensorflow的reduce_sum()方法

作者: theo_NI | 来源:发表于2017-12-11 18:15 被阅读0次

reduce_sum() 就是求和,由于求和的对象是tensor,所以是沿着tensor的某些维度求和。reduction_indices是指沿tensor的哪些维度求和。(可省略不写)

import tensorflow as tf
sess=tf.Session()
s=[[1,1,1],
   [2,2,2]]
a=tf.reduce_sum(s)
print(sess.run(a))   # 9
b=tf.reduce_sum(s,0)
print(sess.run(b))   #  [3 3 3]
c=tf.reduce_sum(s,1)
print(sess.run(c))   #  [3 6]
d=tf.reduce_sum(s,1,keep_dims=True)# [[3],[6]]
print(sess.run(d))
f=tf.reduce_sum(s,[0,1])
print(sess.run(f))    #  9

相关文章

网友评论

      本文标题:tensorflow的reduce_sum()方法

      本文链接:https://www.haomeiwen.com/subject/decwixtx.html