a = tf.Variable(0.0,dtype=tf.float32) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) print(sess.run(a)) a = tf.assign(a,10) print(sess.run(a)) a = tf.assign(a,20) print(sess.run(a))
0.0 10.0 20.0
a = tf.Variable(1,dtype=tf.float32) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) print(sess.run(a)) a = tf.assign_add(a,10) print(sess.run(a)) a = tf.assign_sub(a,20) print(sess.run(a))
1.0 11.0 1.0