How to do a column sum in Tensorflow?

前端 未结 1 1219
谎友^
谎友^ 2021-02-13 01:37

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)
提交回复
热议问题