The Dot Product Between Arrays

--

All the Ways !!!

The dot product or scalar product or inner product between two vectors and of the same size is defined as:

The dot product takes two vectors and returns a single number.

Defining Arrays

nparray1 = np.array([0, 1, 2, 3]) # Define an array
nparray2 = np.array([4, 5, 6, 7]) # Define an array

1. Recommended Way

way_1 = np.dot(nparray1, nparray2)
Output : 38

2. Okayish Way

way_2 = np.sum(nparray1 * nparray2)
Output : 38

3. Geeks way

way_3 = nparray1 @ nparray2
Output : 38

4. Noobs way

#(As you never should do:)
way_4 = 0
for a, b in zip(nparray1, nparray2):
way_4 += a * b
Output : 38

I strongly recommend using np.dot, since it is the only method that accepts arrays and lists without problems !

</happy coding>

--

--