A lab notebook stores a row of real amplitudes a_0, a_1, \dots, a_{N-1}. One step of the search algorithm in this level does something purely arithmetic to such a row: it reflects every entry through the average of the row. With the mean
m = \frac{1}{N}\sum_{i=0}^{N-1} a_i
(in Python m = sum(amps) / len(amps)), every entry a_i is replaced by
a_i' = 2m - a_i .
An entry that sits d below the mean ends up d above it, and the other way round. The mean is computed once, from the original row, and then used for every entry.
Write invert_about_mean(amps) that returns the new row as a list (or numpy array) of the same length.
Examples
Input: amps = [1, 2, 3, 6]
Output: [5.0, 4.0, 3.0, 0.0]
Explanation: the mean is 3, so 1 becomes 2*3 - 1 = 5 and 6 becomes 0.
Input: amps = [0.5, 0.5, -0.5, 0.5]
Output: [0.0, 0.0, 1.0, 0.0]
Explanation: the mean is 0.25; the one negative entry jumps to 0.5 + 0.5 = 1.
Input: amps = [7]
Output: [7.0]
Constraints
- numbers are compared with a tolerance of
1e-6
Goals
- Compute the mean of a list and reflect every entry through it
- See that a number below the average ends up the same distance above it