Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在TensorFlow中平铺变量张量会创建新变量吗?_Python_Machine Learning_Tensorflow - Fatal编程技术网

Python 在TensorFlow中平铺变量张量会创建新变量吗?

Python 在TensorFlow中平铺变量张量会创建新变量吗?,python,machine-learning,tensorflow,Python,Machine Learning,Tensorflow,我有一个(2x1)变量张量,我定义为: W = tf.Variable(tf.random_normal([2, 1])) 因此,(2x1)向量中有2个变量。然后我继续平铺这个张量,如下所示: W = tf.tile(W,tf.constant([1,3])) 我们现在有一个(2x3)张量。我的问题是: 我们知道有6个唯一变量吗?或者这两个唯一变量是否在3列上平铺?它的行为与您预期的一样:原始变量平铺,没有创建变量。很容易检查: import tensorflow as tf W = tf

我有一个(2x1)变量张量,我定义为:

W = tf.Variable(tf.random_normal([2, 1]))
因此,(2x1)向量中有2个变量。然后我继续平铺这个张量,如下所示:

W = tf.tile(W,tf.constant([1,3]))
我们现在有一个(2x3)张量。我的问题是:


我们知道有6个唯一变量吗?或者这两个唯一变量是否在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.]]
Wt
不是变量,无法赋值:

Wt[0,0].assign(1).eval()
# ValueError: Sliced assignment is only supported for variables

您可以查看
tf.get_default_graph().as_graph_def()
的输出,了解实际的图形是什么。您将有一个用于
变量
的op和一个用于
平铺
的op,它们彼此相连,因此只有一个变量