fn

scatter

Tensor
scatter(base_impl: Tensor, dim: int, index: Tensor, src: Tensor, reduce: str | None = ...)
source

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_implTensor
Destination tensor (will be copied — out-of-place).
dimint
Axis along which to scatter.
indexTensor
Integer index tensor; same shape as src.
srcTensor
Values to write.
reducestr= ...
'add' or 'multiply' to disambiguate collisions deterministically.

Returns

Tensor

Updated 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))