flip

nvtripy.flip(input: Tensor, dim: int | Sequence[int] | None = None) Tensor[source]

Reverses the order of elements along the specified dimension(s).

Parameters:
  • input (Tensor) – [dtype=T1] The input tensor.

  • dim (int | Sequence[int] | None) – The dimension(s) that should be reversed. If None, all dimensions will be reversed.

Returns:

[dtype=T1] A new tensor of the same shape as the input.

Return type:

Tensor

DATA TYPE CONSTRAINTS:
Example
1input = tp.reshape(tp.arange(10), (2, 5))
2output = tp.flip(input)  # equivalent to tp.flip(input, dim=[0, 1])
Local Variables
>>> input
tensor(
    [[0, 1, 2, 3, 4],
     [5, 6, 7, 8, 9]], 
    dtype=float32, loc=gpu:0, shape=(2, 5))

>>> output
tensor(
    [[9, 8, 7, 6, 5],
     [4, 3, 2, 1, 0]], 
    dtype=float32, loc=gpu:0, shape=(2, 5))
Example: Reversing only one dimension.
1input = tp.reshape(tp.arange(10), (2, 5))
2output = tp.flip(input, dim=-1)
Local Variables
>>> input
tensor(
    [[0, 1, 2, 3, 4],
     [5, 6, 7, 8, 9]], 
    dtype=float32, loc=gpu:0, shape=(2, 5))

>>> output
tensor(
    [[4, 3, 2, 1, 0],
     [9, 8, 7, 6, 5]], 
    dtype=float32, loc=gpu:0, shape=(2, 5))