Return np.add.reduceat(A, idx). Note that idx is not guaranteed to be increasing - work out what NumPy does for a descending pair before you answer.
np.add.reduceat(A, idx)
idx
Input
A = [0 1 2 3 4 5 6 7 8 9] idx = [0, 5, 2, 8]
Output
[10 5 27 17]
This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.
solve(...)