Skip to content
fn

unbind

→list of Tensor
unbind(input: Tensor, dim: DimLike = ...)

Implementing kernel

C++ engine symbols that back this Python API.

Remove dim and return the slices along it.

Equivalent to [x.select(dim, i) for i in range(x.size(dim))] but implemented as a single op. On the CPU each slice is a view of x's buffer, so writing to one changes x; on metal each slice is a copy.

Parameters

inputTensor
Source tensor.
dimint= 0
Dimension to unbind.

Returns

list of Tensor

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

Notes

The inverse operation is stack along the same dim.

Examples

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