3.8 变量的赋值
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
# 通过变量赋值输出1、2、3...10
import tensorflow as tf
value = tf.Variable(0, name="value")
one = tf.constant(1)
new_value = tf.add(value, one)
update_value = tf.assign(value, new_value)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
sess.run(update_value)
print(sess.run(value))