- tf.identity(input, name=None)
返回一个一模一样的新tensor
示例:
import tensorflow as tf
a = tf.constant(1.0 , tf.float32)
init = tf.global_variables_initializer()
b = tf.identity(a)
with tf.Session() as sess:
sess.run(init)
print(sess.run(a))
print(sess.run(b))
输出:
1.0
1.0
- tf.assign_add(ref, value, use_locking=None, name=None)
通过增加一个值更新张量
示例:
import tensorflow as tf
w = tf.Variable(1.0)
update = tf.assign_add(w , 1.0)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(update))
输出:
2.0
本文介绍了TensorFlow中两个基本操作:使用tf.identity复制张量及tf.assign_add更新张量的值。通过实例展示了如何创建和初始化张量,并进行复制与加法更新。
1万+

被折叠的 条评论
为什么被折叠?



