fn

permute

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

Return a view with dimensions rearranged.

The argument dims is a permutation of range(input.ndim) — the returned tensor's axis i corresponds to input's axis dims[i]. Implemented by stride manipulation; no data is moved.

Parameters

inputTensor
Source tensor.
dimsint or sequence of int= ()
Permutation of the input axes.

Returns

Tensor

View with new strides. Usually non-contiguous — follow with contiguous if a flat layout is required downstream.

Notes

transpose is the rank-2 special case. movedim expresses the same operation when only a few axes move.

Examples

>>> import lucid
>>> x = lucid.zeros(2, 3, 4)
>>> lucid.permute(x, [2, 0, 1]).shape
(4, 2, 3)