Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a column sum in Tensorflow?

What is the equivalent of the following in Tensorflow?

np.sum(A, axis=1)
like image 622
maroxe Avatar asked Feb 28 '16 23:02

maroxe


People also ask

What does tf reduce sum do?

math. reduce_sum. Computes the sum of elements across dimensions of a tensor.

How do you add two tensors in Tensorflow?

add() Function. The tf. add() function returns the addition of two tf. Tensor objects element wise.


1 Answers

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
like image 121
lejlot Avatar answered Sep 28 '22 19:09

lejlot