flopscope.numpy.linalg.cross
fnp.linalg.cross(x1: 'ArrayLike', x2: 'ArrayLike', /, *, axis: 'int' = -1) -> 'FlopscopeArray'[flopscope source][numpy source]
Returns the cross product of 3-element vectors.
Adapted from NumPy docs np.linalg.cross
Delegates to `fnp.cross` which charges `numel(output)` FLOPs.
If x1 and/or x2 are multi-dimensional arrays, then
the cross-product of each pair of corresponding 3-element vectors
is independently computed.
This function is Array API compatible, contrary to flops.cross.
Parameters
- x1:array_like
The first input array.
- x2:array_like
The second input array. Must be compatible with
x1for all non-compute axes. The size of the axis over which to compute the cross-product must be the same size as the respective axis inx1.- axis:int, optional
The axis (dimension) of
x1andx2containing the vectors for which to compute the cross-product. Default:-1.
Returns
- out:ndarray
An array containing the cross products.
See also
Examples
Vector cross-product.
>>> x = flops.array([1, 2, 3])
>>> y = flops.array([4, 5, 6])
>>> flops.linalg.cross(x, y)
array([-3, 6, -3])Multiple vector cross-products. Note that the direction of the cross product vector is defined by the right-hand rule.
>>> x = flops.array([[1,2,3], [4,5,6]])
>>> y = flops.array([[4,5,6], [1,2,3]])
>>> flops.linalg.cross(x, y)
array([[-3, 6, -3],
[ 3, -6, 3]])>>> x = flops.array([[1, 2], [3, 4], [5, 6]])
>>> y = flops.array([[4, 5], [6, 1], [2, 3]])
>>> flops.linalg.cross(x, y, axis=0)
array([[-24, 6],
[ 18, 24],
[-6, -18]])