fn

cat

Tensor
cat(tensors: list[Tensor], dim: DimLike = ...)
source

Concatenate tensors along an existing dimension.

All tensors must share the same shape except along dim. The output dimensionality is unchanged; only the size of dim grows. Contrast with stack, which inserts a new leading dim.

Parameters

tensorslist of Tensor
Tensors to concatenate. Must be non-empty.
dimDimLike= ...
The dimension along which to concatenate.

Returns

Tensor

A newly-allocated tensor — concatenation always copies.

Notes

Mathematically, if x(k)x^{(k)} are the inputs, the result is

y,i,  =  x,iok,(k),ok=j<kx(j).size[dim].y_{\dots, i, \dots} \;=\; x^{(k)}_{\dots, i - o_k, \dots}, \quad o_k = \sum_{j<k} x^{(j)}.\text{size}[\dim] .

Examples

>>> import lucid
>>> a = lucid.tensor([[1, 2]])
>>> b = lucid.tensor([[3, 4]])
>>> lucid.cat([a, b], dim=0)
Tensor([[1, 2],
        [3, 4]])