Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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 matmul运算>;2不起作用_Python_Tensorflow_Rank - Fatal编程技术网

Python 秩的Tensorflow matmul运算>;2不起作用

Python 秩的Tensorflow matmul运算>;2不起作用,python,tensorflow,rank,Python,Tensorflow,Rank,我在Tensorflow文档主页上找到以下内容,用于在秩>2时使用matmul操作: 当我将它插入Python时,它根本不起作用。我明白了 c = tf.matmul(a, b) ValueError: Shape must be rank 2 but is rank 3 有人知道怎么回事吗?你的TensorFlow太老了吗?这是我在版本0.12rc0中得到的 a = tf.constant(np.arange(1,13).astype(np.float32), shape=[2, 2, 3

我在Tensorflow文档主页上找到以下内容,用于在秩>2时使用matmul操作:

当我将它插入Python时,它根本不起作用。我明白了

c = tf.matmul(a, b)
ValueError: Shape must be rank 2 but is rank 3

有人知道怎么回事吗?

你的TensorFlow太老了吗?这是我在版本0.12rc0中得到的

a = tf.constant(np.arange(1,13).astype(np.float32), shape=[2, 2, 3])
b = tf.constant(np.arange(13,25).astype(np.float32), shape=[2, 3, 2])
sess.run(tf.matmul(a, b)) =>

array([[[  94.,  100.],
        [ 229.,  244.]],

       [[ 508.,  532.],
        [ 697.,  730.]]], dtype=float32)

我不熟悉tensorflow,所以我不知道tensorflow数组比numpy数组多多少,但是你可以试试
numpy.dot
(但是上面的维度顺序可能不同)。无论如何,您的tensorflow版本可能比文档对应的版本旧(假设文档是正确的)。谢谢您,但是您的代码给了我相同的错误。。。就在几周前安装了tensorflow,我能得到错误的版本吗?您知道我如何检查当前运行的版本吗?Thanks@user7318197大多数模块都支持
\uuuuu version\uuuu
方法,因此请尝试打印
tf.\uuuu version\uuuu
。好的,谢谢。我得到的答案是“0.11.0”。似乎有一个版本0.12.0,所以直到尝试安装它,看看它是否有帮助。
a = tf.constant(np.arange(1,13).astype(np.float32), shape=[2, 2, 3])
b = tf.constant(np.arange(13,25).astype(np.float32), shape=[2, 3, 2])
sess.run(tf.matmul(a, b)) =>

array([[[  94.,  100.],
        [ 229.,  244.]],

       [[ 508.,  532.],
        [ 697.,  730.]]], dtype=float32)