bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / cross
_ArrayFunctionDispatcher
numpy:cross
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/numeric.py :1554
Signature
def cross ( a , b , axisa = -1 , axisb = -1 , axisc = -1 , axis = None ) Summary
Return the cross product of two (arrays of) vectors.
Extended Summary
The cross product of a and b in is a vector perpendicular to both a and b. If a and b are arrays of vectors, the vectors are defined by the last axis of a and b by default, and these axes can have dimensions 2 or 3. Where the dimension of either a or b is 2, the third component of the input vector is assumed to be zero and the cross product calculated accordingly. In cases where both input vectors have dimension 2, the z-component of the cross product is returned.
Parameters
a: array_likeComponents of the first vector(s).
b: array_likeComponents of the second vector(s).
axisa: int, optionalAxis of
athat defines the vector(s). By default, the last axis.axisb: int, optionalAxis of
bthat defines the vector(s). By default, the last axis.axisc: int, optionalAxis 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.
axis: int, optionalIf defined, the axis of
a,band c that defines the vector(s) and cross product(s). Overridesaxisa,axisbandaxisc.
Returns
c: ndarrayVector cross product(s).
Raises
: ValueErrorWhen the dimension of the vector(s) in
aand/orbdoes not equal 2 or 3.
Notes
Supports full broadcasting of the inputs.
Dimension-2 input arrays were deprecated in 2.0.0. If you do need this functionality, you can use
def cross2d(x, y): return x[..., 0] * y[..., 1] - x[..., 1] * y[..., 0]
Examples
Vector cross-product.import numpy as np x = [1, 2, 3] y = [4, 5, 6] np.cross(x, y)✓
x = [1, 2] y = [4, 5, 6] np.cross(x, y)✓
x = [1, 2, 0] y = [4, 5, 6] np.cross(x, y)✓
x = [1,2] y = [4,5] np.cross(x, y)✓
x = np.array([[1,2,3], [4,5,6]]) y = np.array([[4,5,6], [1,2,3]]) np.cross(x, y)✓
np.cross(x, y, axisc=0)
✓x = np.array([[1,2,3], [4,5,6], [7, 8, 9]]) y = np.array([[7, 8, 9], [4,5,6], [1,2,3]]) np.cross(x, y) np.cross(x, y, axisa=0, axisb=0)✓
See also
- inner
Inner product
- ix_
Construct index arrays.
- linalg.cross
An Array API compatible variation of
np.cross, which accepts (arrays of) 3-element vectors only.- outer
Outer product.
Aliases
-
numpy.cross