cross

cross(x1: array, x2: array, /, *, axis: int = -1) array

Returns the cross product of 3-element vectors.

If x1 and/or x2 are multi-dimensional arrays (i.e., the broadcasted result has a rank greater than 1), then the cross-product of each pair of corresponding 3-element vectors is independently computed.

Parameters:
  • x1 (array) – first input array. Must have a numeric data type. The size of the axis over which the cross product is to be computed must be equal to 3.

  • x2 (array) –

    second input array. Must be broadcast compatible with x1 along all axes other than the axis along which the cross-product is computed (see Broadcasting). The size of the axis over which the cross product is to be computed must be equal to 3. Must have a numeric data type.

    Note

    The compute axis (dimension) must not be broadcasted.

  • axis (int) – the axis (dimension) of x1 and x2 containing the vectors for which to compute the cross product. Should be an integer on the interval [-N, -1], where N is min(x1.ndim, x2.ndim). The function must determine the axis along which to compute the cross product by counting backward from the last dimension (where -1 refers to the last dimension). By default, the function must compute the cross product over the last axis. Default: -1.

Returns:

out (array) – an array containing the cross products. The returned array must have a data type determined by Type Promotion Rules.

Notes

Raises

  • if the size of the axis over which to compute the cross product is not equal to 3 (before broadcasting) for both x1 and x2.

Changed in version 2022.12: Added support for broadcasting.

Changed in version 2022.12: Added complex data type support.

Changed in version 2023.12: Restricted broadcasting to only non-compute axes and required that axis be a negative integer.