我是TensorFlow的初学者,我正在尝试将两个矩阵相乘,但我不断得到一个例外:
ValueError: Shapes TensorShape([Dimension(2)]) and TensorShape([Dimension(None), Dimension(None)]) must have the same rank
Run Code Online (Sandbox Code Playgroud)
这是最小的示例代码:
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}
Run Code Online (Sandbox Code Playgroud)
令人困惑的是,以下非常相似的代码工作正常:
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}
Run Code Online (Sandbox Code Playgroud)
任何人都可以指出问题是什么?我必须在这里遗漏一些明显的东西..
tensorflow ×1