fn
reshape
→Tensorreshape(input: Tensor, shape: int | Sequence[int] = ())Reshape a tensor to shape, returning a view when possible.
The total number of elements must match
(). Unlike view,
reshape may allocate a new contiguous buffer when the
requested layout cannot be expressed by stride manipulation alone
(e.g. after a non-contiguous transpose). Exactly one entry may be
-1, inferred from the remaining sizes.
Parameters
inputTensorSource tensor.
shapeint or sequence of int= ()Target shape. Exactly one entry may be
-1 (auto-inferred).Returns
TensorTensor of the requested shape. View when feasible, otherwise a copy.
Notes
For the strict no-copy contract, use view, which raises if
the layout cannot be expressed as a view. reshape's
flexibility makes it the safer default for general user code.
Examples
>>> import lucid
>>> x = lucid.arange(12)
>>> lucid.reshape(x, (3, 4)).shape
(3, 4)