How to do a column sum in Tensorflow?

前端 未结 1 1074
一生所求
一生所求 2021-02-13 01:46

What is the equivalent of the following in Tensorflow?

np.sum(A, axis=1)
相关标签:
1条回答
  • 2021-02-13 02:14

    There is tf.reduce_sum which is a bit more powerfull tool for doing so.

    # 'x' is [[1, 1, 1]
    #         [1, 1, 1]]
    tf.reduce_sum(x) ==> 6
    tf.reduce_sum(x, 0) ==> [2, 2, 2]
    tf.reduce_sum(x, 1) ==> [3, 3]
    tf.reduce_sum(x, 1, keep_dims=True) ==> [[3], [3]]
    tf.reduce_sum(x, [0, 1]) ==> 6
    
    0 讨论(0)
提交回复
热议问题