fn
unsqueeze
→Tensorunsqueeze(input: Tensor, dim: DimLike)Insert a new size-1 dimension at position dim.
The output has rank input.ndim + 1. Negative dim indexes from
the right (after the new axis is added), so unsqueeze(x, -1)
appends a trailing axis.
Parameters
inputTensorSource tensor.
dimDimLikePosition of the inserted axis.
Returns
TensorView into input with an extra size-1 axis.
Notes
Inverse of squeeze (when squeeze is called with the same
dim). Pair with expand to broadcast scalars or vectors
into higher-rank shapes without copying.
Examples
>>> import lucid
>>> x = lucid.tensor([1, 2, 3])
>>> lucid.unsqueeze(x, 0).shape
(1, 3)