A running club records every member as a vector [resting heart rate, kilometres per week, age] (or any other fixed list of features). The coach wants to see each member compared with the typical member: the vector whose every position is the mean of that column.
Write centre_members(rows) that returns a tuple (typical, compared):
typicalis the list of column means,comparedis a new list of rows, where each row is the member's vector minustypical, position by position. A positive entry means "more than typical", a negative one "less than typical".
The input list must not be changed.
Examples
Input: rows = [[60, 20, 30], [70, 10, 40], [65, 30, 50]]
Output: ([65.0, 20.0, 40.0], [[-5.0, 0.0, -10.0], [5.0, -10.0, 0.0], [0.0, 10.0, 10.0]])
Explanation: the heart rates 60, 70, 65 have mean 65, the distances mean 20, the ages mean 40.
The first member has a heart rate 5 below typical and is 10 years younger than typical.
Input: rows = [[3, -1]]
Output: ([3.0, -1.0], [[0.0, 0.0]])
Constraints
1 <= len(rows) <= 10**4, every row has the same lengthdwith1 <= d <= 20- values are ints or floats; answers are compared with a tolerance of
1e-6
Goals
- Compute the mean vector (centroid) of a dataset column by column
- Centre a dataset by subtracting the centroid from every row
- Read a centred value as above or below typical