In mathematics, the dot product or also known as the scalar product is an algebraic operation that takes two equal-length sequences of numbers and returns a single number. Let us given two vectors A and B, and we have to find the dot product of two vectors.
i: the unit vector along the x directions
j: the unit vector along the y directions
k: the unit vector along the z directions
Then the dot product is calculated as:
Given two vectors A and B as,
Dot Product of Two Vectors in Python
Python provides a very efficient method to calculate the dot product of two vectors. By using numpy.dot() method which is available in the NumPy module one can do so.
numpy.dot(vector_a, vector_b, out = None)
vector_a: [array_like] if a is complex its complex conjugate is used for the calculation of the dot product.
vector_b: [array_like] if b is complex its complex conjugate is used for the calculation of the dot product.
out: [array, optional] output argument must be C-contiguous, and its dtype must be the dtype that would be returned for dot(a,b).
Dot Product of vectors a and b. if vector_a and vector_b are 1D, then scalar is returned
[[5 4] [9 6]]
[[2 4] [6 9]]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.