tf.assign(A, new_number): 这个函数的功能主要是把A的值变为new_number
例如:
输出:
0.0
10.0
开始给A赋值为0,经过tf.assign函数后,把A的值变为10
print("sssssssssss 2 ")
state = tf.Variable(0,name="counter")
one = tf.constant(1)
new_value = tf.add(state, one)
update = tf.assign(state, new_value)
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
# Runthe 'init' op
sess.run(init_op)
# Printthe initial value of 'state'
print(sess.run(state))
# Runthe op that updates 'state' and print 'state'.
for k in range(5):
sess.run(update)
print(sess.run(state))