cross¶
- paddle. cross ( x, y, axis=None, name=None ) [source]
-
Computes the cross product between two tensors along an axis.
Inputs must have the same shape, and the length of their axes should be equal to 3. If axis is not given, it defaults to the first axis found with the length 3.
- Parameters
-
x (Tensor) – The first input tensor.
y (Tensor) – The second input tensor.
axis (int, optional) – The axis along which to compute the cross product. It defaults to the first axis found with the length 3.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor. A Tensor with same data type as x.
Examples
import paddle x = paddle.to_tensor([[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [3.0, 3.0, 3.0]]) y = paddle.to_tensor([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) z1 = paddle.cross(x, y) # [[-1. -1. -1.] # [ 2. 2. 2.] # [-1. -1. -1.]] z2 = paddle.cross(x, y, axis=1) # [[0. 0. 0.] # [0. 0. 0.] # [0. 0. 0.]]