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]]