# For 2-D array, it is matrix multiplication import numpy.matlib
import numpy as np
a =[[1,0],[0,1]]
b =[[4,1],[2,2]]print np.matmul(a,b)
它将产生以下输出 -
[[41][22]]
例子
# 2-D mixed with 1-D import numpy.matlib
import numpy as np
a =[[1,0],[0,1]]
b =[1,2]print np.matmul(a,b)print np.matmul(b,a)
它将产生以下输出 -
[12][12]
例子
# one array having dimensions > 2 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)