【发布时间】:2016-01-20 18:46:30
【问题描述】:
我是 TensorFlow 的初学者,我正在尝试将两个矩阵相乘,但我不断收到异常消息:
ValueError: Shapes TensorShape([Dimension(2)]) and TensorShape([Dimension(None), Dimension(None)]) must have the same rank
这是最小的示例代码:
data = np.array([0.1, 0.2])
x = tf.placeholder("float", shape=[2])
T1 = tf.Variable(tf.ones([2,2]))
l1 = tf.matmul(T1, x)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
sess.run(feed_dict={x: data}
令人困惑的是,以下非常相似的代码可以正常工作:
data = np.array([0.1, 0.2])
x = tf.placeholder("float", shape=[2])
T1 = tf.Variable(tf.ones([2,2]))
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
sess.run(T1*x, feed_dict={x: data}
谁能指出问题所在?我必须在这里遗漏一些明显的东西..
【问题讨论】:
标签: tensorflow