Sub topic 2
Averages: The Sum-of-Values View
This chapter assumes you can simplify fractions, compute percentages, and solve linear equations in one variable.
The arithmetic mean and the sum-of-values view
The arithmetic mean is the sum of the values divided by the count. Equivalently, the sum equals the mean times the count: Sum = Mean × n. Working with the sum, not the mean, makes most average problems easier.
scores = [18, 22, 25, 30, 20]
n = len(scores)
total = sum(scores)
mean = total / n
print(total, mean) # 115 23.0Weighted averages and why ratios act as weights
When groups have different sizes, the combined mean is a weighted average. Each group's mean counts in proportion to its size. If group A has 3 members with mean 10, and group B has 2 members with mean 20, the combined mean is (3 × 10 + 2 × 20) / 5 = 14. The ratio 3:2 supplies the weights, and the result sits closer to 10 because group A is larger.
def weighted_mean(values, weights):
return sum(v * w for v, w in zip(values, weights)) / sum(weights)
print(weighted_mean([10, 20], [3, 2])) # 14.0How an average moves when items are added, removed or replaced
Use the sum to find the change.
| Change | Effect on sum | Effect on mean |
|---|---|---|
| Add x to n items with mean m | +x | (x − m) / (n + 1) |
| Remove x from n items with mean m | −x | (m − x) / (n − 1) |
| Replace a with b in n items | b − a | (b − a) / n |
> The mean rises when the new item is above the old mean, and falls when it is below.
For example, if 5 numbers have mean 20 and a sixth number raises the mean to 22, the new number is 20 + 6 × 2 = 32.
The assumed-mean shortcut
Pick a convenient guess A near the mean. Find each deviation d = x − A, then compute Mean = A + (sum of deviations) / n.
values = [48, 52, 55, 60, 45]
A = 50
mean = A + sum(v - A for v in values) / len(values)
print(mean) # 52.0Exercise
The mean of 6 numbers is 15. One number, 9, is replaced by 21. What is the new mean?
Show answer
The sum rises by 21 − 9 = 12, so the mean rises by 12 / 6 = 2. The new mean is 17.