【发布时间】:2017-12-11 21:51:16
【问题描述】:
我想将行占位符(例如 [1, 2])转换为列占位符,例如 [[1], [2]]
y = tf.placeholder(tf.int32, shape=[None], name='target')
y = tf.reshape(y, (y.shape[0], 1))
init = tf.global_variables_initializer()
with tf.Session() as sess:
init.run()
print(sess.run(y, feed_dict={y:[1,2]}))
但我得到一个错误:
TypeError: Failed to convert object of type <class 'tuple'> to Tensor. Contents: (Dimension(None), 1). Consider casting elements to a supported type.
问题在于y.shape[0] 的使用。 y 的维度定义为None。我也尝试过tf.shape(y),但效果不佳。
【问题讨论】:
标签: python multidimensional-array tensorflow