矩阵乘法np.dot()及np.multipy()区别

1. 线性代数中矩阵乘法: np.dot()

import numpy as np
​
# 2 x 3
matrix1 = np.array([[1, 2, 3], [4, 5, 6]])
​
# 3 x 2
matrix2 = np.array([[1, 2], [3, 4], [5, 6]])
​
multi = np.dot(matrix1, matrix2)
print(multi)
[[22 28]
 [49 64]]

2. 对应元素相乘 np.multiply()或 *

matrix3 = np.array([[1, 2, 3], [4, 5, 6]])
matrix4 = np.array([[1, 2, 3], [4, 5, 6]])
​
multi2 = np.multiply(matrix3, matrix4)
​
print(multi2)
[[ 1  4  9]
 [16 25 36]]
 
原文地址:https://www.cnblogs.com/douzujun/p/10309151.html