a = np.asarray([1,2,3])
b = np.asarray([2,3,4,5])
a.shape
(3,)
b.shape
(4,)
我想要一个 3×4 的矩阵,它是 a 和 b 的乘积。
1
2 * 2 3 4 5
3
np.dot(a, b.transpose())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: objects are not aligned
仅当数组为 2D 时,点积才等价于矩阵乘法,因此 np.dot 不适用。