fn
stack
→Tensorstack(tensors: list[Tensor], dim: DimLike = ...)Stack tensors along a new dimension.
All inputs must share the same shape. The output has rank
input.ndim + 1 — dim controls where the new axis is inserted.
Contrast with cat, which concatenates along an existing dim.
Parameters
tensorslist of TensorEqual-shaped tensors to stack.
dimDimLike= ...Index at which to insert the new dim.
Returns
TensorTensor of shape input.shape with size len(tensors) inserted
at position dim.
Notes
Equivalent to cat([t.unsqueeze(dim) for t in tensors], dim=dim)
but implemented as a single fused copy.
Examples
>>> import lucid
>>> a = lucid.tensor([1, 2])
>>> b = lucid.tensor([3, 4])
>>> lucid.stack([a, b], dim=0).shape
(2, 2)