numpy数组各种乘法

 

 

 

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) # 对应元素相乘
Out[36]:
array([[ 4,  4],
       [10, 12]])

In [37]: np.matmul(a,b) # 矩阵相乘
Out[37]:
array([[12,  9],
       [32, 17]])

In [38]: np.dot(a, b) # 矩阵相乘
Out[38]:
array([[12,  9],
       [32, 17]])

In [39]: np.vdot(a, b) # 对应元素相乘最后相加
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]])

 

转载于:https://www.cnblogs.com/cymwill/p/8876727.html

你可能感兴趣的:(numpy数组各种乘法)