使用 NumPy 并尝试将矩阵相乘有时是行不通的。例如
import numpy as np
x = np.matrix('1, 2; 3, 8; 2, 9')
y = np.matrix('5, 4; 8, 2')
print(np.multiply(x, y))
可以返回
Traceback (most recent call last):
File "vector-practice.py", line 6, in <module>
print(np.multiply(x, y))
ValueError: operands could not be broadcast together with shapes (3,2) (2,2)
我知道我不能将这些形状相乘,但为什么不呢?我可以在纸上将这两个矩阵相乘,那为什么不在 NumPy 中呢?我在这里遗漏了一些明显的东西吗?