mindspore.mint.cross
- mindspore.mint.cross(input, other, dim=None)[source]
Computes the cross product of input and other in dimension dim. input and other must have the same shape, and the size of their dim dimension should be 3. If dim is not specified, it is set to be the first dimension found with the size 3.
- Parameters
input (Tensor) – input is a tensor.
other (Tensor) – The other Tensor, other must have the same shape and type as input input, and the size of their dim dimension should be 3.
dim (int, optional) – dimension to apply cross product in. if dim is None, it is set to be the first dimension found with the size 3. Default:
None
.
- Returns
Tensor, has the same shape and type as input input.
- Raises
TypeError – If input is not a Tensor.
TypeError – If other is not a Tensor.
TypeError – If the type of input is not the same as that of other.
ValueError – If input and other not have the same size, and the size of their dim dimension not be 3.
ValueError – If input and other not have the same shape.
ValueError – If dim is out of range, dim should be [-len(input.shape), len(input.shape)-1].
- Supported Platforms:
Ascend
Examples
>>> from mindspore import Tensor, mint >>> # case 1: dim=None. >>> x = Tensor([[1, 2, 3], [1, 2, 3]]) >>> other = Tensor([[4, 5, 6], [4, 5, 6]]) >>> output = mint.cross(x, other) >>> print(output) [[-3 6 -3] [-3 6 -3]] >>> # case 2: dim=1. >>> x = Tensor([[1, 2, 3], [1, 2, 3]]) >>> other = Tensor([[4, 5, 6], [4, 5, 6]]) >>> output = mint.cross(x, other, dim=1) >>> print(output) [[-3 6 -3] [-3 6 -3]]