np.mean/median/std
Quick summary numbers: the average, the middle value, and how spread out the data is.
In this page:
Syntax
np.mean(arr, axis=axis)
np.median(arr)
np.std(arr)
np.mean/median/std
mean is the arithmetic average, median the middle value, and std the standard deviation, a measure of spread. All accept an axis argument. np.median is a function only, not an array method.
Note:
std uses ddof=0 by default (population); pass ddof=1 for the sample standard deviation.
Example: np.mean/median/std
import numpy as np
a = np.array([2, 4, 4, 4, 5, 5, 7, 9])
print(a.mean())
print(np.median(a))
print(a.std())
print(a.std(ddof=1).round(3))
# Output:
# 5.0
# 4.5
# 2.0
# 2.138
Related Topics
Common Mistakes
- Calling arr.median() which does not exist
- Forgetting ddof for sample statistics
- Averaging integers and expecting an integer
Chapter Summary
- mean, median and std summarize data
- axis controls direction
- Default std is population
- median is only np.median
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: