fn
scatter
→Tensorscatter(base_impl: Tensor, dim: int, index: Tensor, src: Tensor, reduce: str | None = ...)Write src into base_impl along dim at positions index.
Inverse of gather. For each entry of src the destination
is determined by substituting index into the dim coordinate;
all other coords are inherited from the source position. If
multiple sources target the same destination the result is
implementation-defined unless reduce is given.
Parameters
base_implTensorDestination tensor (will be copied — out-of-place).
dimintAxis along which to scatter.
indexTensorInteger index tensor; same shape as
src.srcTensorValues to write.
reducestr= ...'add' or 'multiply' to disambiguate collisions
deterministically.Returns
TensorUpdated tensor of the same shape as base_impl.
Notes
For deterministic accumulation prefer scatter_add.
Examples
>>> import lucid
>>> base = lucid.zeros(3, 4)
>>> idx = lucid.tensor([[0, 1, 2, 0]])
>>> src = lucid.tensor([[1.0, 2.0, 3.0, 4.0]])
>>> lucid.scatter(base, dim=0, index=idx, src=src)
Tensor(shape=(3, 4))