fn
swapaxes
→Tensorswapaxes(x: Tensor, axis0: int, axis1: int)Return x with axes axis0 and axis1 exchanged.
NumPy-style spelling of pairwise axis transposition. Verbose alias of
swapdims; both names refer to the same composite.
Parameters
xTensorInput tensor.
axis0intFirst axis to swap. Negative values count from the end.
axis1intSecond axis to swap. Negative values count from the end.
Returns
TensorTensor with the same data as x but with axis0 and
axis1 exchanged. Where possible Lucid returns a view; if
the underlying storage is non-contiguous, a freshly materialised
tensor is returned (still satisfying value semantics — Lucid
never aliases in a way that would surprise in-place writers).
Notes
For a tensor with shape , the output shape is
Some reference frameworks document swapaxes as having in-place
view semantics — in Lucid it is always a (possibly fresh) value-view.
Examples
>>> import lucid
>>> x = lucid.zeros((2, 3, 4))
>>> lucid.swapaxes(x, 0, 2).shape
(4, 3, 2)