dpnp.linalg.cross

dpnp.linalg.cross(x1, x2, /, *, axis=-1)[source]

Returns the cross product of 3-element vectors.

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 dpnp.cross.

For full documentation refer to numpy.linalg.cross.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- First input array.

  • b ({dpnp.ndarray, usm_ndarray}) -- Second input array. Must be compatible with x1 for 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 in x1.

  • axis (int, optional) -- The axis (dimension) of x1 and x2 containing the vectors for which to compute the cross-product. Default: -1.

Returns:

out -- An array containing the cross products.

Return type:

dpnp.ndarray

See also

dpnp.cross

Similar function with support for more keyword arguments.

Examples

Vector cross-product.

>>> import dpnp as np
>>> x = np.array([1, 2, 3])
>>> y = np.array([4, 5, 6])
>>> np.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 = np.array([[1, 2, 3], [4, 5, 6]])
>>> y = np.array([[4, 5, 6], [1, 2, 3]])
>>> np.linalg.cross(x, y)
array([[-3,  6, -3],
       [ 3, -6,  3]])
>>> x = np.array([[1, 2], [3, 4], [5, 6]])
>>> y = np.array([[4, 5], [6, 1], [2, 3]])
>>> np.linalg.cross(x, y, axis=0)
array([[-24,  6],
       [ 18, 24],
       [-6,  -18]])