tensorflow的assgin方法

时间:2022-02-09 16:38:52

官网API是这么说的

tensorflow的assgin方法

This operation outputs a Tensor that holds the new value of 'ref' after the value has been assigned. This makes it easier to chain operations that need to use the reset value.

该操作输出一个tensor。当委派结束后,ref就会有新的值value。就是把value值赋值给ref

使用:

     A = tf.Variable(tf.constant(0.0), dtype=tf.float32)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(A))
print(sess.run(tf.assign(A, 10)))
print(sess.run(A))

输出:

    tensorflow的assgin方法