Mean of Each Group
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
1 <= len(values) <= 1001 <= k <= 10-100 <= values[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Multiplication TableMedium
- Order by ScoreMedium
- Pairs Hitting TargetMedium
- Pairwise SumsMedium
- Path LengthMedium
- Rank of Each ScoreMedium
- Ranks Without GapsMedium
- Record HighsMedium