
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Return the cross product of two (arrays of) vectors with different dimensions in Python
To compute the cross product of two vectors, use the numpy.cross() method in Python Numpy. The method returns c, the Vector cross product(s). The 1st parameter is a, the components of the first vector(s). The 2nd parameter is b, the components of the second vector(s). The 3rd parameter is axisa, the axis of a that defines the vector(s). By default, the last axis. The 4th parameter is axisb, the axis of b that defines the vector(s). By default, the last axis.
The 5th parameter is axisc, the axis of c containing the cross product vector(s). Ignored if both input vectors have dimension 2, as the return is scalar. By default, the last axis. The 6th parameter is the axis, if defined, the axis of a, b and c that defines the vector(s) and cross product(s). Overrides axisa, axisb and axisc.
Steps
At first, import the required library −
import numpy as np
Creating two vectors with different dimensions. We have inserted elements of int type −
arr1 = [13, 11, 19] arr2 = [19, 10]
Display the vectors −
print("Vector 1...\n", arr1) print("\nVector 2...\n", arr2)
To compute the cross product of two vectors, use the numpy.cross() method in Python Numpy −
print("\nResult...\n",np.cross(arr1, arr2))
Example
import numpy as np # Creating two vectors with different dimensions # We have inserted elements of int type arr1 = [13, 11, 19] arr2 = [19, 10] # Display the vectors print("Vector 1...\n", arr1) print("\nVector 2...\n", arr2) # To compute the cross product of two vectors, use the numpy.cross() method in Python Numpy # The method returns c, the Vector cross product(s). print("\nResult...\n",np.cross(arr1, arr2))
Output
Vector 1... [13, 11, 19] Vector 2... [19, 10] Result... [-190 361 -79]
- Related Articles
- Return the cross product of two (arrays of) vectors in Python
- Return the multiple vector cross product of two (arrays of) vectors in Python
- Get the Kronecker product of two arrays with different dimensions in Python
- Return the dot product of two vectors in Python
- Return the multiple vector cross product of two vectors and change the orientation of the result in Python
- Return the dot product of two multidimensional vectors in Python
- Compute the tensor dot product for arrays with different dimensions in Python
- Return the outer product of two masked arrays with different shapes in Numpy
- Return the inner product of two masked arrays with different shapes in Numpy
- C++ Program for dot product and cross product of two vectors
- C++ Program to Compute Cross Product of Two Vectors
- Compute the tensor dot product for arrays with different dimensions with double contraction in Python
- Compute the tensor dot product for arrays with different dimensions with array-like axes in Python
- Compute the tensor dot product for arrays with different dimensions over specific axes in Python
- Get the Kronecker product of arrays with 4D and 3D dimensions in Python
