a = np.asarray([1,2,3])
b = np.asarray([2,3,4,5])
a.shape
(3,)
b.shape
(4,)
我想要一个 3 x 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
当数组是二维时,点积仅相当于矩阵乘法,因此 np.dot 不起作用。
This is np.outer(a, b) http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.outer.html:
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]])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)