🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEscipy

scipy Documentation

LOADING ENGINE...

stats.norm()

AI & DATA SCIENCE // stats-norm

scipy.stats.norm is an object representing the normal (Gaussian) distribution, providing methods to compute its probability density, cumulative probability, and to generate random samples from it.

Syntax

scipy.stats.norm(loc=0, scale=1)
scipy.stats.norm.pdf(x, loc=0, scale=1)

Deep Dive Course

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.

editor.html
from scipy import stats

dist = stats.norm(loc=100, scale=15)
print(round(dist.cdf(115), 4))
localhost:3000

2Practical Example

Here is a real-world application of stats.norm() showing how it is used in production SciPy code.

editor.html
from scipy import stats

print(round(stats.norm.pdf(0, loc=0, scale=1), 4))
localhost:3000

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.

editor.html
from scipy import stats

dist = stats.norm(loc=100, scale=15)
print(round(dist.cdf(115), 4))
localhost:3000

Examples

Example 01Basic Usage
from scipy import stats

dist = stats.norm(loc=100, scale=15)
print(round(dist.cdf(115), 4))
Example 02Advanced Example
from scipy import stats

print(round(stats.norm.pdf(0, loc=0, scale=1), 4))

Best Practices

  • Use .cdf() to answer 'what proportion of the distribution falls below, or above, a given value' questions, rather than manually integrating the density function
  • Create a frozen distribution object when calling multiple methods against the same fixed parameters, instead of repeating loc/scale on every call
  • Use .rvs() with an explicit random_state/seed argument for reproducible random samples in tests or demonstrations

Interview Question

What's the practical difference between calling stats.norm.pdf(x) and stats.norm.cdf(x)?

Hint: Think about whether each one answers a question about a single point's density, or an accumulated probability.

pdf(x), the probability density function, describes the relative likelihood of the distribution taking on a value near x — for a continuous distribution like the normal, this is a density, not a probability itself, and it can be read as describing the height of the distribution's characteristic bell curve at that specific point. cdf(x), the cumulative distribution function, instead gives the actual probability that a randomly drawn value from the distribution is less than or equal to x, accumulating the density from negative infinity up to that point — it's the function you'd use to answer a question like what fraction of values fall below this threshold, which pdf() alone can't directly answer.

Exercises

MediumPractice using stats.norm() in a real scenario.
View Solution
from scipy import stats

dist = stats.norm(loc=100, scale=15)
print(round(dist.cdf(115), 4))

Frequently Asked Questions

What's the practical difference between calling stats.norm.pdf(x) and stats.norm.cdf(x)?

pdf(x), the probability density function, describes the relative likelihood of the distribution taking on a value near x — for a continuous distribution like the normal, this is a density, not a probability itself, and it can be read as describing the height of the distribution's characteristic bell curve at that specific point. cdf(x), the cumulative distribution function, instead gives the actual probability that a randomly drawn value from the distribution is less than or equal to x, accumulating the density from negative infinity up to that point — it's the function you'd use to answer a question like what fraction of values fall below this threshold, which pdf() alone can't directly answer.

Related Functions

stats-normalteststats-kstestnp-random-normal