fn

movedim

Tensor
movedim(input: Tensor, source: int | Sequence[int], destination: int | Sequence[int])
source

Move one or more dimensions to new positions.

The remaining dims keep their relative order. Equivalent to permute with an automatically computed permutation but easier to read when only a few axes change.

Parameters

inputTensor
Source tensor.
sourceint or sequence of int
Original dimension positions.
destinationint or sequence of int
Target dimension positions (must have the same length as source).

Returns

Tensor

View with rearranged strides.

Notes

Common use: convert between channel-first (N, C, H, W) and channel-last (N, H, W, C) by movedim(x, 1, -1).

Examples

>>> import lucid
>>> x = lucid.zeros(2, 3, 4, 5)
>>> lucid.movedim(x, 1, -1).shape
(2, 4, 5, 3)