fn
swapdims
→Tensorswapdims(x: Tensor, dim0: int, dim1: int)Swap two named dimensions of a tensor.
Returns a view (or, if not contiguous, a freshly materialised tensor)
whose dimensions dim0 and dim1 have been exchanged. All other
dimensions retain their position.
Parameters
xTensorInput tensor.
dim0intFirst dimension to swap. Negative values count from the end.
dim1intSecond dimension to swap. Negative values count from the end.
Returns
TensorTensor with the same data as x but with axes dim0 and
dim1 exchanged.
Notes
For a tensor with shape , the result has shape
Equivalent to swapaxes; both names are provided for parity
with NumPy and reference-framework conventions.
Examples
>>> import lucid
>>> x = lucid.zeros((2, 3, 4))
>>> lucid.swapdims(x, 0, 2).shape
(4, 3, 2)