Scatter-Add by Index
mediumnumpy_reductionsImplement accumulate_at(values, idx, n).
Given 1D arrays values and idx (same length, idx values in [0, n)),
return an array out of length n where out[k] is the sum of all
values[j] for which idx[j] == k. No for/while loops.
Constraints
- no scipy, sklearn
- no for/while loops
Your solution
Edit accumulate_at and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
np.bincount(idx, weights=values, minlength=n) sums values into bins by index.