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.

  • x2 (array) –

    second input array. Must be compatible with x1 for all non-compute axes (see Broadcasting). The size of the axis over which to compute the cross product must be the same size as the respective axis in x1. 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. Must be an integer on the interval [-N, N), where N is the rank (number of dimensions) of the shape determined according to Broadcasting. If specified as a negative integer, 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

Changed in version 2022.12: Added support for broadcasting.

Changed in version 2022.12: Added complex data type support.

Raises

  • if provided an invalid axis.

  • if the size of the axis over which to compute the cross product is not equal to 3.

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