fn

transpose

Tensor
transpose(input: Tensor)
source

Swap the last two dimensions of input.

The zero-argument form: for a 2-D tensor this is the matrix transpose; for higher-rank tensors the final two axes are swapped (batch dims are preserved). Implemented as a stride manipulation — no data is copied.

Parameters

inputTensor
Source tensor with ndim >= 2.

Returns

Tensor

Non-contiguous view with last two axes swapped.

Notes

To swap arbitrary axes use permute or movedim. Because the output is non-contiguous, downstream ops requiring a flat layout should follow with contiguous.

Examples

>>> import lucid
>>> x = lucid.zeros(2, 3, 4)
>>> lucid.transpose(x).shape
(2, 4, 3)