[英]Tensorflow matmul operation for rank>2 does not work
我在Tensorflow文檔主頁上找到以下內容,以便在rank> 2時使用matmul操作:
https://www.tensorflow.org/api_docs/python/math_ops/matrix_math_functions#matmul
# 3-D tensor `a`
a = tf.constant(np.arange(1,13), shape=[2, 2, 3]) => [[[ 1. 2. 3.]
[ 4. 5. 6.]],
[[ 7. 8. 9.]
[10. 11. 12.]]]
# 3-D tensor `b`
b = tf.constant(np.arange(13,25), shape=[2, 3, 2]) => [[[13. 14.]
[15. 16.]
[17. 18.]],
[[19. 20.]
[21. 22.]
[23. 24.]]]
c = tf.matmul(a, b) => [[[ 94 100]
[229 244]],
[[508 532]
[697 730]]]
當我用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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.