tensorflow笔记--变量

Dependencies:
tensorflow: 1.1.0
"""
import tensorflow as tf

var = tf.Variable(0)    # our first variable in the "global_variable" set

add_operation = tf.add(var, 1)
update_operation = tf.assign(var, add_operation)

with tf.Session() as sess:
    # once define variables, you have to initialize them by doing this
    sess.run(tf.global_variables_initializer())
    for _ in range(3):
        sess.run(update_operation)
        print(sess.run(var))
posted @ 2021-08-26 18:46  kuanleung  阅读(9)  评论(0)    收藏  举报  来源