fn

flip

Tensor
flip(input: Tensor, dims: int | Sequence[int])
source

Reverse the order of elements along the specified dims.

Each listed dimension is reversed independently. Equivalent to indexing with [::-1] along those axes but expressed as a single op that returns a contiguous result.

Parameters

inputTensor
Source tensor.
dimsint or sequence of int
Dimension(s) to reverse.

Returns

Tensor

Tensor of the same shape as input with the listed dims reversed.

Notes

Flipping is involutive: flip(flip(x, d), d) == x.

Examples

>>> import lucid
>>> x = lucid.tensor([[1, 2], [3, 4]])
>>> lucid.flip(x, dims=[0])
Tensor([[3, 4],
        [1, 2]])