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
原文地址:https://www.cnblogs.com/wzdLY/p/10066749.html
时间: 2024-11-06 11:46:07