Skip to content
fn

movedim

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

Implementing kernel

C++ engine symbols that back this Python API.

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

input with the axes moved — a view on the CPU, a copy on metal.

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)