Skip to content
Related Articles

Related Articles

How to compute the cross product of two given vectors using NumPy?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 29 Aug, 2020

Let’s see the program to compute the cross product of two given vectors using NumPy. For finding the cross product of two given vectors we are using numpy.cross() function of NumPy library.

Syntax: numpy.cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None)[

Return: cross product of two (arrays of) vectors.

Let’s see the examples:

Example 1: Cross product of 1d-arrays.

Python3




# import library
import numpy as np
  
# declare vectors
x = [1, 2]
y = [3, 4]
  
# find cross product of
# two given vectors
result = np.cross(x, y)
  
# show the result
print(result)

Output:

-2

Example 2: Cross product of 2d-arrays.

Python3




# import library
import numpy as np
  
# declare vectors
x = [[1, 2], [3, 4]]
y = [[5, 6], [7, 8]]
  
# find cross product of
# two given vectors
result = np.cross(x, y)
  
# show the result
print(result)

Output:

[-4 -4]
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!