莫烦tensorflow(3)-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)

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))

上一篇:JavaWeb程序利用Servlet的对SQLserver增删改查操作


下一篇:莫烦tensorflow(9)-Save&Restore