fn

unbind

tuple of Tensor
unbind(input: Tensor, dim: DimLike = ...)
source

Remove dim and return a tuple of views along it.

Equivalent to [x.select(dim, i) for i in range(x.size(dim))] but implemented as a single op. The resulting tensors share storage with x.

Parameters

inputTensor
Source tensor.
dimDimLike= ...
Dimension to unbind.

Returns

tuple of Tensor

input.size(dim) views, each of rank input.ndim - 1.

Notes

The inverse operation is stack along the same dim. Useful for unpacking batched sequences without copying.

Examples

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