transpose(input: Tensor, dim0: _int | None = ..., dim1: _int | None = ...)Implementing kernel
C++ engine symbols that back this Python API.Reverse the axes of input, or swap the two named.
Without axes this is NumPy's transpose: the order of every axis is
reversed, which for a 2-D tensor is the matrix transpose (.T is the
same; .mT swaps only the last two). With dim0 and dim1,
those two are swapped, as the reference framework's transpose does.
On the CPU the result is a view with the strides permuted; on metal the
data is copied.
Parameters
inputTensorSource tensor with
ndim >= 2.dim0int= ...The two axes to swap. Give both, or neither to reverse them all.
dim1int= ...The two axes to swap. Give both, or neither to reverse them all.
Returns
Tensorinput with its axes reversed or the two swapped — a
non-contiguous view on the CPU, a copy on metal.
Raises
TypeErrorIf only one of
dim0 and dim1 is given.Notes
To reorder more than two 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
(4, 3, 2)
>>> lucid.transpose(x, 0, 1).shape
(3, 2, 4)