tensorflow assign 发表于 2019-05-08 | 分类于 tensorflow | 评论数: tf.assign 简单解释 op = x.assign(y) 将y的值赋值给x,执行sess.run(op)后,x的值就变成和y一样了。 代码示例 代码地址 12345678910111213141516171819202122232425262728293031323334import tensorflow as tf# 声明两个Variablex1 = tf.Variable([3,4])x2 = tf.Variable([9,1])# y是将x2 assign 给x1的opy = x1.assign(x2)with tf.Session() as sess: sess.run(tf.global_variables_initializer()) xx1 = sess.run(x1) # 输出x1 print(xx1) # [3 4] xx2 = sess.run(x2) # 输出x2 print(xx2) # [9 1] print(sess.run(x1)) # [3 4] # 执行y操作 yy = sess.run(y) print(yy) # [9 1] # 发现x1已经用x2赋值了 print(sess.run(x1)) # [9 1] print(sess.run(x2)) # [9 1]