Search code examples
pandasnumpytensorflowtensorboard

Undesired output with tf.reduce_sum()


Using tensorflow reduce_sum but getting undesired output. I am trying to calculate the below thing:

x = tf.constant([[1,1,1],[1,1,1]])
tf.reduce_sum(x,0)



expected output = [2, 2, 2]

actual output = <tf.Tensor 'Sum:0' shape=() dtype=int32>

Solution

  • If you want to display, you need to be in a session and use eval()

    import tensorflow as tf
    sess = tf.InteractiveSession()
    
    x = tf.constant([[1,1,1],[1,1,1]])
    tf.reduce_sum(x,0).eval()