fn
expand
→Tensorexpand(input: Tensor, sizes: int | Sequence[int] = ())Return a view with singleton dimensions broadcast to new sizes.
For each axis whose current size is 1, expand replaces it with
the requested size by setting the stride along that axis to 0. Axes
that already have non-1 sizes must be passed as -1 (or the same
size). No data is copied.
Parameters
inputTensorSource tensor.
sizesint or sequence of int= ()Target sizes.
-1 means "keep current size".Returns
TensorA view sharing storage with input.
Notes
expand is the in-place-style cousin of broadcast_to;
they produce equivalent views but expand requires the input to
already have a 1-sized dim where the expansion happens. Writing into
the result is undefined because multiple logical entries alias the
same physical element.
Examples
>>> import lucid
>>> x = lucid.tensor([[1.0], [2.0], [3.0]]) # shape (3, 1)
>>> lucid.expand(x, 3, 4).shape
(3, 4)