使用tf.reduce_sum()的不需要的输出

问题描述 投票:0回答:1

使用tensorflow reduce_sum但获得不需要的输出。我想计算下面的事情:

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>
pandas numpy tensorflow tensorboard
1个回答
1
投票

如果要显示,则需要进入会话并使用eval()

import tensorflow as tf
sess = tf.InteractiveSession()

x = tf.constant([[1,1,1],[1,1,1]])
tf.reduce_sum(x,0).eval()
© www.soinside.com 2019 - 2024. All rights reserved.