norm can be used in two styles: calling scipy.stats.norm(loc, scale) creates a frozen distribution object with fixed parameters that you can then repeatedly query, or you can call methods like norm.pdf(), norm.cdf(), or norm.rvs() directly, passing loc and scale as arguments each time. .pdf() gives the probability density at a point, .cdf() gives the cumulative probability of a value being less than or equal to x, useful for questions like what fraction of the distribution falls below this value, and .rvs() generates random samples drawn from the distribution.
1Understanding stats.norm()
norm can be used in two styles: calling scipy.stats.norm(loc, scale) creates a frozen distribution object with fixed parameters that you can then repeatedly query, or you can call methods like norm.pdf(), norm.cdf(), or norm.rvs() directly, passing loc and scale as arguments each time. .pdf() gives the probability density at a point, .cdf() gives the cumulative probability of a value being less than or equal to x, useful for questions like what fraction of the distribution falls below this value, and .rvs() generates random samples drawn from the distribution.
Create a frozen distribution object, with fixed loc and scale, when you'll be calling several different methods against the same fixed parameters — it's both more convenient and slightly more efficient than repeating loc and scale as arguments to every individual method call.
from scipy import stats
dist = stats.norm(loc=100, scale=15)
print(round(dist.cdf(115), 4))2Practical Example
Here is a real-world application of stats.norm() showing how it is used in production SciPy code.
from scipy import stats
print(round(stats.norm.pdf(0, loc=0, scale=1), 4))3Best Practices
Follow these guidelines when working with stats.norm():
1. Use .cdf() to answer 'what proportion of the distribution falls below, or above, a given value' questions, rather than manually integrating the density function
2. Create a frozen distribution object when calling multiple methods against the same fixed parameters, instead of repeating loc/scale on every call
3. Use .rvs() with an explicit random_state/seed argument for reproducible random samples in tests or demonstrations
Tip: Create a frozen distribution object, with fixed loc and scale, when you'll be calling several different methods against the same fixed parameters — it's both more convenient and slightly more efficient than repeating loc and scale as arguments to every individual method call.
from scipy import stats
dist = stats.norm(loc=100, scale=15)
print(round(dist.cdf(115), 4))