【发布时间】:2017-12-09 15:59:38
【问题描述】:
我正在预处理一个 numpy 数组,并希望将其作为 tensorflow 变量输入。我试过遵循其他堆栈交换建议,但到目前为止没有成功。我想看看我是否在这里做错了什么。
npW = np.zeros((784,10))
npW[0,0] = 20
W = tf.Variable(tf.convert_to_tensor(npW, dtype = tf.float32))
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
print("npsum", np.sum(npW))
print(tf.reduce_sum(W))
这就是结果。
npsum 20.0
Tensor("Sum:0", shape=(), dtype=float32)
我不知道为什么 W 变量的减少总和仍然为零。我在这里错过了什么吗?
【问题讨论】:
标签: python-3.x numpy tensorflow