小编abo*_*ora的帖子

如何为TensorFlow变量赋值?

我试图在python中为tensorflow变量赋一个新值.

import tensorflow as tf
import numpy as np

x = tf.Variable(0)
init = tf.initialize_all_variables()
sess = tf.InteractiveSession()
sess.run(init)

print(x.eval())

x.assign(1)
print(x.eval())
Run Code Online (Sandbox Code Playgroud)

但我得到的输出是

0
0
Run Code Online (Sandbox Code Playgroud)

所以价值没有改变.我错过了什么?

python variable-assignment neural-network deep-learning tensorflow

73
推荐指数
3
解决办法
8万
查看次数