np.mean/median/std/var
Four core measures: average, middle, spread and squared spread.
In this page:
Syntax
np.mean(arr)
np.median(arr)
np.std(arr)
np.var(arr)
np.mean/median/std/var
mean, median, std and var summarize the centre and spread of data. Variance is the average squared distance from the mean and std is its square root. On 2-D data, pass axis to summarize columns or rows.
Note:
var equals std squared.
Example: np.mean/median/std/var
import numpy as np
data = np.array([[1, 2, 3], [4, 5, 6]])
print(np.mean(data), np.median(data))
print(np.var(data).round(3), np.std(data).round(3))
print("column means:", np.mean(data, axis=0))
# Output:
# 3.5 3.5
# 2.917 1.708
# column means: [2.5 3.5 4.5]
Related Topics
Common Mistakes
- Forgetting that var units are squared
- Ignoring outliers that distort mean
- Using the wrong axis
Chapter Summary
- mean gives the centre
- median resists outliers
- var is std squared
- axis picks column or row summaries
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: