np.random.normal/uniform
normal draws bell-curve numbers with any mean and spread; uniform draws evenly spread numbers from any range.
In this page:
Syntax
np.random.normal(loc, scale, size)
np.random.uniform(low, high, size)
np.random.normal/uniform
np.random.normal(loc, scale, size) draws from a normal distribution with mean loc and standard deviation scale. np.random.uniform(low, high, size) draws floats evenly between two values. These are the most flexible everyday distributions.
Note:
With a large sample, the mean of normal values lands close to loc.
Example: np.random.normal/uniform
import numpy as np
np.random.seed(10)
heights = np.random.normal(170, 8, size=1000)
print(round(heights.mean(), 1), round(heights.std(), 1))
u = np.random.uniform(5, 10, size=5)
print(u.round(2))
# Output:
# 169.9 7.5
# [7.37 8.9 9.25 7.29 8.28]
Related Topics
Common Mistakes
- Passing variance as scale instead of standard deviation
- Mixing up low and high in uniform
- Small samples not matching expected values
Chapter Summary
- normal takes mean and std
- uniform takes low and high
- scale is standard deviation
- Large samples approach the true values
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: