tensorflow 莫烦视频学习笔记 变量 (二)


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.initialize_all_variables()

with tf.Session() as sess:
    sess.run(init)
    for _ in range(3):
        sess.run(update)
        print(sess.run(state))
posted @ 2022-08-19 22:59  luoganttcc  阅读(11)  评论(0编辑  收藏  举报