Dre*_*rew 2 python machine-learning tensorflow
我有一个(2x1)可变张量,我定义为:
W = tf.Variable(tf.random_normal([2, 1]))
Run Code Online (Sandbox Code Playgroud)
因此 (2x1) 向量中有 2 个变量。然后我继续像这样平铺这个张量:
W = tf.tile(W,tf.constant([1,3]))
Run Code Online (Sandbox Code Playgroud)
我们现在有一个 (2x3) 张量。我的问题是这样的:
我们知道有 6 个唯一变量吗?或者这 2 个唯一变量是否平铺在 3 列上?
它的行为与您预期的一样:原始变量被平铺,并且没有变量创建。很容易检查:
import tensorflow as tf
W = tf.Variable(tf.zeros((2,1)))
Wt = tf.tile(W, (1,3))
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
print(Wt.eval())
# [[ 0. 0. 0.]
# [ 0. 0. 0.]]
W[0,0].assign(1).eval()
print(Wt.eval())
# [[ 1. 1. 1.]
# [ 0. 0. 0.]]
Run Code Online (Sandbox Code Playgroud)
Wt 不是变量,不能赋值:
Wt[0,0].assign(1).eval()
# ValueError: Sliced assignment is only supported for variables
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |