python:在numpy中将两个1d矩阵相乘 [英] python: Multiply two 1d matrices in numpy

查看:421
本文介绍了python:在numpy中将两个1d矩阵相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

a.shape

(3,)

b.shape

(4,)

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

I want a 3 by 4 matrix that's the product of a and b

1
2    *    2 3 4 5
3

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

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

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

点积仅在数组为2d时等效于矩阵乘法,因此np.dot不起作用.

dot product is only equivalent to matrix multiplication when the array is 2d, so np.dot doesn't work.

推荐答案

这是 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆