python:在numpy中将两个一维矩阵相乘

Job*_*obs 3 python numpy matrix

a = np.asarray([1,2,3])

b = np.asarray([2,3,4,5])

a.shape

(3,)

b.shape

(4,)
Run Code Online (Sandbox Code Playgroud)

我想要一个 3 x 4 矩阵,它是 a 和 b 的乘积

1
2    *    2 3 4 5
3
Run Code Online (Sandbox Code Playgroud)

np.dot(a, b.transpose())

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: objects are not aligned
Run Code Online (Sandbox Code Playgroud)

当数组是二维时,点积仅相当于矩阵乘法,因此 np.dot 不起作用。

use*_*ica 7

这是np.outer(a, b)

In [2]: np.outer([1, 2, 3], [2, 3, 4, 5])
Out[2]: 
array([[ 2,  3,  4,  5],
       [ 4,  6,  8, 10],
       [ 6,  9, 12, 15]])
Run Code Online (Sandbox Code Playgroud)