Understanding Dispersion Measures in NumPy : Range, Variance, and Standard Deviation
What is Dispersion (Data Spread)?
Understanding Dispersion Measures in NumPy : Range, Variance, and Standard Deviation
What is Dispersion (Data Spread)?
In simple terms, dispersion (or spread) tells us how spread out the data values are.
- If data values are very close to each other → Low Dispersion
- If data values are far apart → High Dispersion
Example
Dataset A (Low Dispersion)
Marks: 85, 87, 86, 88, 84
All marks are close to each other. Average ≈ 86
This dataset has low dispersion.
Dataset B (High Dispersion)
Marks: 45, 92, 35, 95, 78
The marks vary a lot, from 35 to 95. Average ≈ 69
This dataset has high dispersion.

Common Ways to Measure Dispersion
1. Range (Simplest Method)
Range is the difference between the largest and smallest value.
Formula:
Range = Maximum Value − Minimum Value
Example:
Marks: 45, 67, 78, 89, 95
Range = 95 − 45 = 50
Limitation: It uses only two values and can be strongly affected by extreme values (outliers).

2. Variance
Variance measures how far data values are from the average (mean).
Example:
Data: 2, 4, 6, 8
Mean = 5
Differences from the mean:
2 − 5 = -3
4 − 5 = -1
6 − 5 = 1
8 − 5 = 3
Square the differences:
- 9, 1, 1, 9
Variance = (9 + 1 + 1 + 9) / 4 = 5

3. Standard Deviation
Standard deviation is the square root of variance.
Formula:
Standard Deviation = √Variance
Using the previous example:
Variance = 5
Standard Deviation = √5 ≈ 2.236
Meaning: On average, the data values are about 2.24 units away from the mean.

Real-Life Examples
Cricket Scores
Consistent Player (Low Dispersion)
Scores: 45, 52, 48, 50, 47
The scores are similar and predictable.
Inconsistent Player (High Dispersion)
Scores: 12, 87, 5, 102, 8
The scores vary greatly.

Stock Market
Low Risk Stock
Prices: 100, 102, 101, 99, 100
Prices change very little.
High Risk Stock
Prices: 80, 150, 60, 200, 50
Prices fluctuate significantly.

Key Idea
- Low Dispersion → Data is more consistent and predictable.
- High Dispersion → Data is more variable and less predictable.

Specific Example : Dispersion Measures
Dataset: Marks of 10 Students (Out of 100)
Data:
48, 52, 55, 60, 65, 72, 78, 80, 85, 90
Step 1: Range (Simplest Measure)
- Maximum value = 90
- Minimum value = 48
Range = 90 − 48 = 42
Meaning: The marks are spread across 42 points.
Step 2: Mean (Average)
We first calculate the mean because Variance and Standard Deviation depend on it.
Sum of all marks:
48 + 52 + 55 + 60 + 65 + 72 + 78 + 80 + 85 + 90 = 685
Mean = 685 ÷ 10 = 68.5
Step 3: Variance
Find the difference between each mark and the mean, square the difference, and then calculate the average.
| Marks | Difference from Mean | Squared Difference |
| ----- | -------------------- | ------------------ |
| 48 | 48 − 68.5 = -20.5 | 420.25 |
| 52 | -16.5 | 272.25 |
| 55 | -13.5 | 182.25 |
| 60 | -8.5 | 72.25 |
| 65 | -3.5 | 12.25 |
| 72 | +3.5 | 12.25 |
| 78 | +9.5 | 90.25 |
| 80 | +11.5 | 132.25 |
| 85 | +16.5 | 272.25 |
| 90 | +21.5 | 462.25 |

Total of squared differences = 1928.5
Variance = 1928.5 ÷ 10 = 192.85
Step 4: Standard Deviation (Most Important)
Standard Deviation = √Variance
SD = √192.85 ≈ 13.89
Meaning: On average, each student’s score is about 13.89 points away from the mean (68.5).

NumPy Code for Dispersion Measures
Here is a clean Python program that calculates the main dispersion measures using NumPy.
import numpy as np
# Dataset
marks = np.array([48, 52, 55, 60, 65, 72, 78, 80, 85, 90])
print("Dataset:", marks)
print("=" * 40)
# 1. Range
data_range = np.max(marks) - np.min(marks)
print(f"1. Range : {data_range}")
# 2. Mean
mean = np.mean(marks)
print(f"2. Mean : {mean}")
# 3. Variance
variance = np.var(marks) # Population variance (default)
print(f"3. Variance : {variance:.4f}")
# 4. Standard Deviation
std_dev = np.std(marks) # Population standard deviation (default)
print(f"4. Standard Deviation : {std_dev:.4f}")
# 5. Sample Variance
variance_sample = np.var(marks, ddof=1)
print(f"5. Sample Variance : {variance_sample:.4f}")
# 6. Sample Standard Deviation
std_dev_sample = np.std(marks, ddof=1)
print(f"6. Sample Std Dev : {std_dev_sample:.4f}")
Expected Output
Dataset: [48 52 55 60 65 72 78 80 85 90]
========================================
1. Range : 42
2. Mean : 68.5
3. Variance : 192.8500
4. Standard Deviation : 13.8863
5. Sample Variance : 214.2778
6. Sample Std Dev : 14.6375
Understanding the Results
Range
Shows the difference between the highest and lowest values.
Range = Maximum Value - Minimum Value
In this dataset
90 - 48 = 42
Mean
The average value of all marks.
Mean = Sum of Values / Number of Values
Result
68.5
Variance
Measures how far the data values are spread from the mean.
np.var(marks)
Result
192.85
A larger variance means the data is more spread out.
Standard Deviation
Shows the spread of the data in the same unit as the original values.
np.std(marks)
Result
13.8863
On average, the marks are about 13.89 points away from the mean.

Summary

These measures help you understand how closely grouped or widely spread your data is around the average value.
메타데이터
- post_id
- 326ca7a6cd0e
- slug
- understanding-dispersion-measures-in-numpy-range-variance-and-standard-deviation-326ca7a6cd0e
- url
- https://medium.com/@codeswithpankaj/understanding-dispersion-measures-in-numpy-range-variance-and-standard-deviation-326ca7a6cd0e
- canonical_url
- https://medium.com/@codeswithpankaj/understanding-dispersion-measures-in-numpy-range-variance-and-standard-deviation-326ca7a6cd0e
- author_url
- https://medium.com/@codeswithpankaj
- status
- ok
- fetched_at
- 2026-06-21 07:44:09