Skip to content
fn

permute

→Tensor
permute(input: Tensor, dims: _int | Sequence[_int])

Implementing kernel

C++ engine symbols that back this Python API.

Return input with its 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]. On the CPU the result is a view of input's buffer with its strides permuted — no data moves, and a write through it reaches input; on metal the data is copied into the new order.

Parameters

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

Returns

Tensor

input with its axes in the new order — a view on the CPU, a contiguous copy on metal.

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)