两个二维数组的 np.dot [英] np.dot of two 2D arrays
本文介绍了两个二维数组的 np.dot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用 numpy 的新手,很抱歉,如果这听起来很明显,我确实在发布之前尝试通过 stackoverflow 进行搜索..
I am new to using numpy so sorry if this sounds obvious, I did try to search through stackoverflow before I post this though..
我有两个列表列表";长度为 n 的 numpy 数组(在下面的示例中 n = 3)
I have two "list of lists" numpy arrays of length n (n = 3 in the example below)
a = np.array([[1, 2], [3, 4], [5, 6]])
b = np.array([[2, 2], [3, 3], [4, 4]])
我想得到一个一维数组,其中包含每个对应索引处列表的点积,即
I want to get a 1d array with the dot product of the lists at each corresponding index, i.e.
[(1*2 + 2*2), (3*3 + 4*3), (5*4 + 6*4)]
[6, 21, 44]
我应该怎么做?提前致谢!
how should I go about doing it? thanks in advance!
推荐答案
你可以这样做
np.sum(a*b,axis=1)
这篇关于两个二维数组的 np.dot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文