Premium problem68. Means of Subsets

Hard Locked

Given a vector D and a same-size integer vector S of subset indices, return the mean of D within each subset:

  • entry i is the mean of the D values whose S entry equals i
  • i runs from 0 up to the largest value in S

Input

D = [0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
S = [0 1 2 3 0 1 2 3 0 1]

Output

[4. 5. 4. 5.]

Premium problem

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

Implement solve(...)