fn
gather
→Tensorgather(input: Tensor, indices: Tensor, dim: DimLike = ...)Gather values along dim according to indices.
For each output position the value is read from input with
indices substituted for the dim-th coordinate. All other
coordinates are inherited from the output position itself — a
"row-wise" lookup.
Parameters
inputTensorSource tensor.
indicesTensorInteger tensor whose shape matches
input except possibly
along dim. Values must be in [0, input.size(dim)).dimDimLike= ...Axis along which to gather.
Returns
TensorTensor with the same shape as indices.
Notes
Mathematically,
Inverse op is scatter.
Examples
>>> import lucid
>>> x = lucid.tensor([[1, 2, 3], [4, 5, 6]])
>>> idx = lucid.tensor([[0, 2], [1, 1]])
>>> lucid.gather(x, idx, dim=1)
Tensor([[1, 3],
[5, 5]])