Various multiplications of numpy arrays

 

 

 

In [34]: a
Out[34]:
array([[1, 4],
       [5, 6]])

In [35]: b
Out[35]:
array([[4, 1],
       [2, 2]])

In [ 36]: np.multiply(a,b) #Multiply the corresponding elements 
Out[36 ]:
array([[ 4,  4],
       [10, 12]])

In [ 37]: np.matmul(a,b) #Matrix multiplication Out 
[37 ]:
array([[12,  9],
       [32, 17]])

In [ 38]: np.dot(a, b) #Matrix multiplication Out 
[38 ]:
array([[12,  9],
       [32, 17]])

In [ 39]: np.vdot(a, b) #Multiply the corresponding elements and add them together 
Out[39]: 30

In [40]: np.outer(a, b) # 外积
Out[40]:
array([[ 4,  1,  2,  2],
       [16,  4,  8,  8],
       [20,  5, 10, 10],
       [24,  6, 12, 12]])

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324536388&siteId=291194637