pythonnumpynumpy-ndarray

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!


Solution

  • You can do this

    np.sum(a*b,axis=1)