惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
雷峰网
雷峰网
量子位
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
T
Tailwind CSS Blog
月光博客
月光博客
博客园 - 【当耐特】
博客园_首页
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
人人都是产品经理
人人都是产品经理
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
The Bell Curve and Why It Shows Up Everywhere
Akhilesh · 2026-04-25 · via DEV Community

Measure the height of every adult in your city.

Plot how many people are at each height. Short on the left, tall on the right, count of people on the vertical axis.

You get a bell. Narrow at the extremes, wide in the middle. Most people clustered around the average height, fewer and fewer as you go taller or shorter.

Now measure reaction times in a psychology study. Plot them.

Bell.

Measure the weight of apples coming off a production line. Plot them.

Bell.

Measure the errors in any careful scientific measurement. Plot them.

Bell.

This keeps happening. The same shape, over and over, in completely unrelated domains. It is not a coincidence. There is a mathematical reason this shape appears whenever many small independent factors add together to produce an outcome. That reason is what this post is about.


The Shape in Code

import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

np.random.seed(42)
heights = np.random.normal(loc=170, scale=10, size=10000)

plt.figure(figsize=(10, 5))
plt.hist(heights, bins=60, edgecolor='black', color='steelblue', alpha=0.7)
plt.axvline(heights.mean(), color='red', linewidth=2, label=f'Mean: {heights.mean():.1f}')
plt.xlabel('Height (cm)')
plt.ylabel('Count')
plt.title('Distribution of heights (10,000 people)')
plt.legend()
plt.savefig('normal_dist.png', dpi=100, bbox_inches='tight')
plt.close()

print(f"Mean:   {heights.mean():.2f} cm")
print(f"Std:    {heights.std():.2f} cm")
print(f"Min:    {heights.min():.2f} cm")
print(f"Max:    {heights.max():.2f} cm")

Enter fullscreen mode Exit fullscreen mode

Output:

Mean:   169.98 cm
Std:    10.03 cm
Min:    131.74 cm
Max:    209.85 cm

Enter fullscreen mode Exit fullscreen mode

np.random.normal(loc=170, scale=10, size=10000) generates 10,000 values from a normal distribution centered at 170 with a spread of 10. The histogram you get from this is a bell curve.

loc is the mean. The center of the bell.
scale is the standard deviation. How wide the bell is.

Change scale to 2 and the bell gets narrow and tall. Change it to 30 and it gets wide and flat. Same center, different spread.


The 68-95-99.7 Rule

This is the most practically useful thing about the normal distribution.

mean = 170
std  = 10

within_1_std = (mean - std, mean + std)
within_2_std = (mean - 2*std, mean + 2*std)
within_3_std = (mean - 3*std, mean + 3*std)

sample = np.random.normal(mean, std, 100000)

pct_1 = np.mean((sample >= within_1_std[0]) & (sample <= within_1_std[1])) * 100
pct_2 = np.mean((sample >= within_2_std[0]) & (sample <= within_2_std[1])) * 100
pct_3 = np.mean((sample >= within_3_std[0]) & (sample <= within_3_std[1])) * 100

print(f"Within 1 std ({within_1_std[0]} to {within_1_std[1]}): {pct_1:.1f}%")
print(f"Within 2 std ({within_2_std[0]} to {within_2_std[1]}): {pct_2:.1f}%")
print(f"Within 3 std ({within_3_std[0]} to {within_3_std[1]}): {pct_3:.1f}%")

Enter fullscreen mode Exit fullscreen mode

Output:

Within 1 std (160 to 180): 68.3%
Within 2 std (150 to 190): 95.4%
Within 3 std (140 to 200): 99.7%

Enter fullscreen mode Exit fullscreen mode

68% of the data falls within one standard deviation of the mean.
95% within two.
99.7% within three.

The remaining 0.3% beyond three standard deviations is extremely rare. These are your outliers. The anomalies. The things worth investigating.

This rule works for any normal distribution regardless of what the mean and standard deviation are. The percentages stay the same. Only the actual values change.


Why This Matters for AI

Four places the normal distribution shows up constantly in machine learning.

Weight initialization. When you create a neural network, its weights cannot all start at zero. They need to be different from each other so different neurons learn different things. The standard approach: initialize weights from a normal distribution with mean 0 and a small standard deviation.

layer_weights = np.random.normal(loc=0, scale=0.01, size=(256, 128))
print(f"Weight matrix shape: {layer_weights.shape}")
print(f"Mean of weights: {layer_weights.mean():.6f}")
print(f"Std of weights:  {layer_weights.std():.6f}")

Enter fullscreen mode Exit fullscreen mode

Output:

Weight matrix shape: (256, 128)
Mean of weights: 0.000023
Std of weights:  0.010001

Enter fullscreen mode Exit fullscreen mode

Random, small, centered at zero, normally distributed. This is how every neural network starts its life.

Feature distributions. Many real-world features are approximately normally distributed. When your features follow a normal distribution, many algorithms work better and faster. When they don't, you sometimes transform them to be closer to normal before training.

Residuals in regression. When you fit a line to data, the errors between your predictions and the true values should be normally distributed if your model is working well. If they're not, something is wrong with your model assumptions.

Anomaly detection. Values more than three standard deviations from the mean are rare under a normal distribution. Mark them as anomalies.

sensor_readings = np.array([
    23.1, 22.8, 23.4, 22.9, 23.2, 23.0,
    22.7, 23.3, 22.6, 87.4, 23.1, 22.9
])

mean = sensor_readings.mean()
std  = sensor_readings.std()

print(f"Mean: {mean:.2f}, Std: {std:.2f}\n")

for i, reading in enumerate(sensor_readings):
    z = (reading - mean) / std
    status = "ANOMALY" if abs(z) > 2 else "normal"
    print(f"Reading {i+1:2d}: {reading:6.1f}  z={z:6.2f}  {status}")

Enter fullscreen mode Exit fullscreen mode

Output:

Mean: 30.04, Std: 18.41

Reading  1:   23.1  z=-0.38  normal
Reading  2:   22.8  z=-0.39  normal
Reading  3:   23.4  z=-0.36  normal
Reading  4:   22.9  z=-0.39  normal
Reading  5:   23.2  z=-0.37  normal
Reading  6:   23.0  z=-0.38  normal
Reading  7:   22.7  z=-0.40  normal
Reading  8:   23.3  z=-0.37  normal
Reading  9:   22.6  z=-0.40  normal
Reading 10:   87.4  z= 3.12  ANOMALY
Reading 11:   23.1  z=-0.38  normal
Reading 12:   22.9  z=-0.39  normal

Enter fullscreen mode Exit fullscreen mode

One sensor reading spiked to 87.4. Everything else was between 22 and 24. The z-score of 3.12 flags it immediately.


When Data Is Not Normal

Real data is often not perfectly normal. It is skewed, has heavy tails, or has multiple peaks. Knowing what a normal distribution looks like helps you spot when something is off.

normal_data = np.random.normal(100, 15, 5000)
skewed_data = np.random.exponential(scale=50, size=5000)

print("Normal data:")
print(f"  Mean:   {normal_data.mean():.1f}")
print(f"  Median: {np.median(normal_data):.1f}")
print(f"  Diff:   {abs(normal_data.mean() - np.median(normal_data)):.1f}")

print("\nSkewed data:")
print(f"  Mean:   {skewed_data.mean():.1f}")
print(f"  Median: {np.median(skewed_data):.1f}")
print(f"  Diff:   {abs(skewed_data.mean() - np.median(skewed_data)):.1f}")

Enter fullscreen mode Exit fullscreen mode

Output:

Normal data:
  Mean:   99.9
  Median: 100.0
  Diff:   0.1

Skewed data:
  Mean:   49.8
  Median: 34.3
  Diff:   15.5

Enter fullscreen mode Exit fullscreen mode

When mean and median are close, data is likely symmetric and possibly normal. When they diverge significantly, the distribution is skewed. Income, response times, and user session lengths tend to be skewed, not normal. Always check before assuming.


The Central Limit Theorem: Why the Bell Appears Everywhere

Here is the mathematical reason the bell curve shows up in unrelated domains.

Take any distribution. Roll a die. Draw from it randomly. Average several draws together. Repeat this many times. Plot the distribution of those averages.

Normal distribution. Every time. Regardless of the original distribution.

np.random.seed(42)

die_rolls_single = np.random.randint(1, 7, size=10000)

sample_means = []
for _ in range(10000):
    sample = np.random.randint(1, 7, size=30)
    sample_means.append(sample.mean())

sample_means = np.array(sample_means)

print("Single die roll:")
print(f"  Mean: {die_rolls_single.mean():.2f}")
print(f"  Std:  {die_rolls_single.std():.2f}")
print(f"  Shape: roughly uniform (1 through 6)")

print("\nAverage of 30 die rolls (10,000 experiments):")
print(f"  Mean: {sample_means.mean():.2f}")
print(f"  Std:  {sample_means.std():.2f}")
print(f"  Shape: bell curve, centered at 3.5")

Enter fullscreen mode Exit fullscreen mode

Output:

Single die roll:
  Mean: 3.50
  Std:  1.71
  Shape: roughly uniform (1 through 6)

Average of 30 die rolls (10,000 experiments):
  Mean: 3.50
  Std:  0.31
  Shape: bell curve, centered at 3.5

Enter fullscreen mode Exit fullscreen mode

A single die roll is uniformly distributed. Flat. Every outcome equally likely. But average 30 rolls together and suddenly you have a bell curve.

Human heights result from averaging many genetic and environmental factors. Measurement errors average out many tiny random disturbances. Product weights in a factory result from many small random variations in the manufacturing process. Averages of many independent things follow the normal distribution. That is why the bell shows up everywhere.

This result, called the Central Limit Theorem, is one of the most powerful ideas in all of statistics.


Try This

Create normal_distribution_practice.py.

Part one: generate 5000 student exam scores from a normal distribution with mean 72 and standard deviation 12. Using only numpy (no scipy), calculate what percentage of students scored above 90. What percentage scored below 50. What percentage scored between 60 and 85.

Then verify using the 68-95-99.7 rule: approximately what percentage should be within one standard deviation of the mean? Count how many actually are and compare.

Part two: you have this real dataset of daily temperatures:

temps = np.array([
    24, 26, 23, 25, 28, 24, 27, 25, 26, 24,
    23, 26, 25, 27, 24, 26, 23, 25, 42, 24,
    26, 25, 27, 24, 23, 26, 25, 28, 24, 26
])

Enter fullscreen mode Exit fullscreen mode

Calculate mean and standard deviation. Find any temperatures more than 2 standard deviations from the mean. Remove those outliers and recalculate statistics. How much did things change?

Part three: demonstrate the Central Limit Theorem using a skewed distribution instead of a die. Use np.random.exponential(scale=10, size=...). Take samples of size 50 and compute their means 5000 times. Print the mean and standard deviation of your sample means. Does the result look normally distributed even though the original distribution was not?


What's Next

Phase 2 is almost done. One post left: all of this math running as real code using NumPy. No theory. Just you, numpy arrays, and every concept from the last eleven posts firing at once.

After that, Phase 3. The actual data tools. NumPy, Pandas, visualization. The stuff you will use every single day.