Numpy-matmul

提供:Dev Guides
移動先:案内検索

numpy.matmul()

  • numpy.matmul()*関数は、2つの配列の行列積を返します。 2次元配列の通常の積を返しますが、いずれかの引数の次元が2より大きい場合、最後の2つのインデックスにあるマトリックスのスタックとして扱われ、それに応じてブロードキャストされます。

一方、いずれかの引数が1次元配列である場合、その次元に1を追加することにより行列に昇格され、乗算後に削除されます。

# For 2-D array, it is matrix multiplication
import numpy.matlib
import numpy as np

a = [[b = [[4,1],[2,2]]
print np.matmul(a,b)

それは次の出力を生成します-

[[Example

[source,prettyprint,notranslate]

#1次元と混合した2次元インポートnumpy.matlib import numpy as np

a = [[b = [1,2] print np.matmul(a、b)print np.matmul(b、a)

It will produce the following output −

[source,result,notranslate]
=== Example

[source,prettyprint,notranslate]

#次元が2より大きい1つの配列import numpy.matlib import numpy as np

a = np.arange(8).reshape(2,2,2)b = np.arange(4).reshape(2,2)print np.matmul(a、b)

It will produce the following output −

[source,result,notranslate]

[[