首页 > 其他 > 详细

TensorFlow 变量Variable

时间:2018-09-22 16:42:00      阅读:156      评论:0      收藏:0      [点我收藏+]
import tensorflow as tf

state = tf.Variable(0, name=counter)  # 定义了名字是counter,初始值为0的计数器
print(state.name)

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

init = tf.initialize_all_variables()    # 在tf中定义变量Variable 一定要初始化

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

 

TensorFlow 变量Variable

原文:https://www.cnblogs.com/francischeng/p/9690269.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!