簡體   English   中英

Tensorflow tf.matmul示例不正確?

[英]Tensorflow tf.matmul example is incorrect?

我閱讀了tf.matmul的官方文檔,我理解了第一個例子。 這是一個簡單的[2,3] x [3,2]操作:

a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3])

b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2])

c = tf.matmul(a, b) => [[58 64]
                    [139 154]]

但是,第二個例子似乎很奇怪:

a = tf.constant(np.arange(1, 13, dtype=np.int32),
            shape=[2, 2, 3])

b = tf.constant(np.arange(13, 25, dtype=np.int32),
            shape=[2, 3, 2])

c = tf.matmul(a, b) => [[[ 94 100]
                     [229 244]],
                    [[508 532]
                     [697 730]]]

為什么允許形狀[2,2,3]的矩陣乘以[2,3,2]?

從同一頁面( https://web.archive.org/web/20170223153510/https://www.tensorflow.org/api_docs/python/tf/matmul ):

返回:與ab相同類型的Tensor ,其中每個最內部矩陣是ab相應矩陣的乘積,例如,如果所有轉置或伴隨屬性都為False
output [...,i,j] = sum_k( a [...,i,k] * b [...,k,j]),對於所有索引i,j。

因此,允許形狀[2,2,3]的矩陣與[2,3,2]相乘。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM