Dot Product and Numpy

@S18CRX0120
So prateek bhaiya executed the following command

a = np.array([1,2,3,4])
b = np.array([1,2,3,4])

print(a.dot(b))
and the output came as 30

while explaining he drew a as a 1x4 matrix
and b as a 4x1 matrix. my question is isn’t b is also a matrix of 1x4 matrix? and how exactly does dot multiplication takes place in vectors?
Shouldn’t we do a.dot(b.T)??

Hey @Bhawna, in numpy.dot If both a and b are 1-D arrays, it is inner product of vectors. That is simply by element wise square.

You can do as matrix multiplication as well, but than you a array must have shape (1,4) and b must be (4,1). You can read more about .dot function in numpy’s original documentation.

Hope this resolved your doubt.
:blush:

@S18CRX0120
It means that in documentation,for 1 D array it is already mentioned that it is inner product of vectors

Hey @Bhawna, yes, assume that function will check first if both are 1-D , if both are 1-D than it will multiply them element wise and sum the resultant.

ok…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.