Tensorflow学习三Variable

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)#将new_value赋值给state
init = tf.initialize_all_variables() # must have if define variable
with tf.Session() as sess:
    sess.run(init)
    for _ in range(3):
        sess.run(update)
        print(sess.run(state))

猜你喜欢

转载自blog.csdn.net/weixin_43408956/article/details/93380392
今日推荐