注册 登录
编程论坛 Python论坛

为什么会出现重复结果

peizeyu 发布于 2018-11-04 22:26, 1379 次点击
>>> import tensorflow as tf
>>> state = tf.Variable(0, name='counter')
>>> one = tf.constant(1)
>>> new_value = tf.add(state, one)
>>> update = tf.assign(state, new_value)
>>> init = tf.global_variables_initializer()
>>>
>>> with tf.Session() as sess:
...     sess.run(init)
...     for _ in range(3):
...             sess.run(update)
...             print(sess.run(state))


1
1
2
2
3
3
0 回复
1