Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

scipy.stats.norm provides methods to calculate normal-distribution densities and probabilities, find quantiles, generate random values, and get central intervals. Its default is the standard normal distribution; set loc to the mean and scale to the standard deviation when you need another normal distribution.

Set the normal distribution’s parameters

Use norm from scipy.stats. With no parameters, it represents the standard normal distribution, with mean 0 and standard deviation 1. For another normal distribution, pass loc for the mean and scale for the standard deviation. The scale must be positive.

from scipy.stats import norm

mu = 5
sigma = 2
x = 6

rv = norm(loc=mu, scale=sigma)

For repeated calculations with the same parameters, create a frozen distribution as above, then call methods on rv. For example, rv.cdf(x) evaluates the cumulative probability at x. SciPy documents both the distribution and its methods in the norm API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a method based on what you need

Method Input Result Use it to answer
pdf(x) A value Density at that value What is the curve’s density at x?
cdf(x) A value Probability accumulated up to that value What is the probability of a draw being at or below x?
ppf(q) A cumulative probability The corresponding quantile What value marks cumulative probability q?
rvs(size=n) A requested output size Random variates How can I simulate observations?
interval(confidence) A probability between 0 and 1 Endpoints of an equal-tailed interval Which central interval contains that share of the distribution?

The examples below use rv, the distribution with mean 5 and standard deviation 2. Each method also accepts the parameters directly, such as norm.cdf(x, loc=mu, scale=sigma). SciPy’s probability distributions tutorial shows array-like inputs for distribution calculations and examples of these methods.

#1 Best Overall

Use pdf for density, not point probability

rv.pdf(x) returns the probability density at x, not the probability that a continuous random variable equals that exact value. For a continuous distribution, probabilities are associated with ranges; the area under the density curve over a range gives the probability of falling in it.

For a standard normal value z, the density is exp(-z**2 / 2) / sqrt(2*pi). For a normal distribution with mean mu and standard deviation sigma, standardize the input as z = (x - mu) / sigma and divide the standard-normal density by sigma.

Rank #2
Sale
Statistics Laminate Reference Chart: Parameters, Variables, Intervals, Proportions (Quickstudy: Academic )
  • This guide is a perfect overview for the topics covered in introductory statistics courses.

Use cdf for probability up to a value

rv.cdf(x) returns the probability that a draw is less than or equal to x. For example, norm.cdf(0) is 0.5 for the standard normal: half of its probability lies at or below zero.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from scipy.stats import norm

# Standard normal cumulative probability at 0
norm.cdf(0)  # 0.5

# Cumulative probabilities at multiple values
norm.cdf([-1, 0, 1])

Because the methods accept array-like inputs, you can calculate results for a list or NumPy array without calling the method separately for each value.

Rank #3

Use ppf to find a quantile

rv.ppf(q) is the inverse of the CDF: it returns the value at cumulative probability q. Pass a probability between 0 and 1. For the standard normal, norm.ppf(0.5) is 0, the median.

# Find the value at the 90th percentile
rv.ppf(0.90)

Use rvs to generate random values

Call rvs with size to specify how many variates to generate. If you need repeatable output, provide a random state as well:

samples = norm.rvs(
    loc=5,
    scale=2,
    size=100,
    random_state=42
)

A common mistake is to write norm.rvs(5) intending to request five draws. The positional argument is interpreted as loc, not size; the sample count remains at its default. Use the explicit keyword size=5 when five draws are wanted. SciPy calls out this positional-argument trap in its distribution tutorial.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use interval for central distribution coverage

rv.interval(confidence) returns the endpoints of an equal-tailed interval containing the requested probability of the distribution. For example, with a symmetric normal distribution, the interval is centered on its mean:

rv.interval(0.95)

This is a central interval of the distribution, not automatically a confidence interval for an unknown parameter estimated from data. A parameter confidence interval depends on the inferential model and the estimator’s uncertainty. The SciPy reference guide’s interval description defines the result in terms of the proportion of the distribution contained between the endpoints.

Check your installed SciPy version

The cited API reference is for SciPy 1.16.2, while the tutorial is for SciPy 1.18.0 and the interval reference guide is an older 0.13.0 page. These pages document the concepts described here, but signatures or behavior can vary by release. Consult the documentation matching your installed SciPy version for version-specific details.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.