莫凡Tensorflow视频学习003-Variable初步了解

import tensorflow as tf

#state = tf.Variable(0, name = 'counter')
state = tf.Variable(0)
one = tf.constant(1)

new_value = tf.add(state, one)
update = tf.assign(state, new_value)

init = tf.initialize_all_variables()

with tf.Session() as sess:
    sess.run(init)
    for _ in range(3):
        sess.run(update)
        print(sess.run(state))

结果:


猜你喜欢

转载自blog.csdn.net/weixin_42142612/article/details/80849403