What is the cross product of two vectors?
Let’s say a and b are two three-dimensional vectors, i.e. both the vectors have 3 components. The cross product of these two vectors is defined as:
Here, c is another vector of the same dimension that is perpendicular to both a and b. So, we can also say,
Here, Θ is the angle between a and b. And ||a|| and ||b|| are the magnitudes of the vectors a and b, respectively.
How to calculate the cross product of two vectors using Python NumPy?
We can use the following Python code to compute the cross product of two three-dimensional vectors.
import numpy a = numpy.array([1, 2, 3]) b = numpy.array([4, 5, 6]) c = numpy.cross(a, b) print("a: \n", a) print("b: \n", b) print("The cross product of a and b: \n", c)
Here, a and b are two row vectors with three elements in each. We are using the numpy.cross() function to compute the cross product of a and b.
The output of the mentioned program will be:
a: [1 2 3] b: [4 5 6] The cross product of a and b: [-3 6 -3]






0 Comments