What is the equivalent of the following in Tensorflow?
np.sum(A, axis=1)
math. reduce_sum. Computes the sum of elements across dimensions of a tensor.
add() Function. The tf. add() function returns the addition of two tf. Tensor objects element wise.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With