FunctionRacerProblemsRace

Mean of Each Group

MediumNumPyPython

labels[i] is the group (0 to k - 1) of values[i]. Return the mean of each group, in group order. A group with no values has mean 0.0. No loops: for and while are not allowed.

Example 1

labels [0,2,0,2,2]
values [4,1,6,2,3]
k 4
returns [5.0,0.0,2.0,0.0]

Group 0 has 4 and 6, group 2 has 1, 2 and 3. Groups 1 and 3 are empty.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems