Python 初始化张量变量无元素仅形状

Python 初始化张量变量无元素仅形状,python,arrays,tensorflow,Python,Arrays,Tensorflow,我想初始化张量变量数组以通过tf.concat存储值。 维度为?,初始值为tf.Variable[]。 尺寸是?、512怎么样? 多谢各位 我成功地做到了 #Initialize Variable center_features= tf.Variable(tf.zeros([1,512]),dtype=tf.float32) #Add vector center_features= tf.concat([center_features,added_vectors]) #Cheat remo

我想初始化张量变量数组以通过tf.concat存储值。 维度为?,初始值为tf.Variable[]。 尺寸是?、512怎么样? 多谢各位

我成功地做到了

#Initialize Variable
center_features= tf.Variable(tf.zeros([1,512]),dtype=tf.float32) 
#Add vector 
center_features= tf.concat([center_features,added_vectors]) 
#Cheat remove the first redundant vector
m = tf.range(1, tf.shape(center_features)[0], 1) 
center_feature = tf.gather(center_features,m)

在构建图时,必须完全了解TensorFlow中变量的形状。不支持动态大小的变量。非常感谢!。但是我指的是用形状?初始化数组的情况,数组的秩是1,tf。变量[]可以使用吗?所以我想用形状数组是?,?或者?512,数组的秩是2。您的意思是像tf.Variable[[]]一样吗?或者tf.Variable[[0]*512]?我不理解你的评论。当我设置tf.Variable[]时,我得到了array?,所以,我想创建一个带有shape?,512或?,的数组?,?。如何设置tf.Variable。非常感谢你!我成功地做到了。初始化变量输出列表\u 1=tf.Variabletf.zeros[1512],dtype=tf.float32添加向量输出列表\u 1=tf.concat[output\u list\u 1,added\u vectors]作弊删除第一个冗余向量m=tf.range1,tf.shapecenter\u features[0],1中心\u feature=tf.gathercenter\u features,m