Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

np.dot of two 2D arrays

I am new to using numpy so sorry if this sounds obvious, I did try to search through stackoverflow before I post this though..

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!

like image 403
minovsky Avatar asked Oct 16 '25 18:10

minovsky


1 Answers

You can do this

np.sum(a*b,axis=1)
like image 77
meTchaikovsky Avatar answered Oct 18 '25 07:10

meTchaikovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!