Skip to content

mlx equivalent to np.add.at / torch.Tensor.scatter_add_ #1317

Answered by awni
louisamand asked this question in Q&A
Discussion options

You must be logged in to vote

We have something like a scatter add in MLX:

import mlx.core as mx

idx = mx.array([0, 1, 2, 2, 1, 0])
b = mx.array([0.1, 9, -1, 4, 3, 2])
a = mx.zeros(shape=3)

a = a.at[idx].add(b)

docs: https://ml-explore.github.io/mlx/build/html/python/_autosummary/mlx.core.array.at.html#mlx.core.array.at

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@louisamand
Comment options

Answer selected by louisamand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants