Premium problem65. Accumulate by Index List

Hard Locked

Accumulate the elements of vector X into an array F using the index list I, and return F:

  • F[I[k]] += X[k] for every k
  • F starts all-zero, sized to cover the largest index in I

Input

X = [1, 2, 3, 4, 5, 6]
I = [1, 3, 9, 3, 4, 1]

Output

[0. 7. 0. 6. 5. 0. 0. 0. 0. 3.]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)