October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Use scipy.stats.norm: pdf, cdf, ppf, rvs, and interval

Use scipy.stats.norm to calculate normal densities and probabilities, find quantiles, simulate values, and get central intervals. Learn how loc and scale work.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

scipy.stats.norm provides methods to evaluate normal-distribution density, calculate cumulative probabilities, find quantiles, generate random values, and return central intervals. By default it represents the standard normal distribution; set loc to the mean and scale to the standard deviation for another normal distribution.

Set up the normal distribution

Import norm from scipy.stats. Its default parameters are loc=0 and scale=1, the standard normal distribution. In this API, loc is the mean, and scale is the standard deviation.

As an Amazon Associate I earn from qualifying purchases.

from scipy.stats import norm

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

Use the resulting frozen distribution, rv, when you want multiple calculations to share the same parameters. For example, rv.cdf(x) and rv.ppf(q) make the selected mean and standard deviation explicit in the object setup. You can also pass loc and scale directly to individual norm methods. See the SciPy norm API reference; check the documentation for your installed SciPy release for version-specific details.

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

Choose the method for the quantity you have

What you have What you want Method
A value, such as x Density at that value pdf(x)
A value, such as x Probability of a draw being at or below it cdf(x)
A cumulative probability, such as q The value at that quantile ppf(q)
A distribution and requested draw count Simulated values rvs(size=n)
A requested central coverage probability The interval endpoints interval(confidence)

These methods accept array-like inputs for vectorized calculations. SciPy’s probability distributions tutorial demonstrates passing both a list and a NumPy array to cdf.

#1 Best Overall

Evaluate density with pdf

pdf(x, loc=mu, scale=sigma) evaluates the probability density at x. For a standard normal input 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; the density is the standard-normal density at z, divided by sigma.

A PDF value is a density, not the probability of observing exactly that value. For a continuous distribution, use cdf or a difference between CDF values to calculate probability over a range.

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.

Calculate cumulative probability with cdf

cdf(x, loc=mu, scale=sigma) returns the probability that a draw is at or below x. To calculate the probability of a draw falling between a and b, subtract the lower cumulative probability from the upper one:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
probability_between = norm.cdf(b, loc=mu, scale=sigma) - norm.cdf(a, loc=mu, scale=sigma)

For the standard normal, norm.cdf(0) is 0.5. The same method works with arrays, so you can calculate cumulative probabilities for several values in one call.

Rank #3

Find a quantile with ppf

ppf(q, loc=mu, scale=sigma) is the inverse of the CDF: it returns the value whose cumulative probability is q. Use it when you know a probability and need the corresponding cutoff. For example, norm.ppf(0.5) returns 0.0 for the standard normal median. Supply the same loc and scale as the distribution of interest when finding a quantile for a nonstandard normal distribution.

Generate simulated values with rvs

Use rvs to draw random variates. Set size to the number of values you want; pass loc and scale by keyword to make the distribution parameters clear.

draws = norm.rvs(loc=5, scale=2, size=100)

For reproducible results, pass a fixed random-state value or generator using random_state, in accordance with the API for your SciPy version. A common trap is writing norm.rvs(5) to request five draws: the positional argument is interpreted as loc, not size, so the default sample count remains one. The SciPy tutorial specifically cautions against this positional-argument mistake.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Get a central interval with interval

interval(confidence, loc=mu, scale=sigma) returns the endpoints of an equal-tailed interval containing the requested probability of the distribution. Because the normal distribution is symmetric, this central interval is centered on its mean. For example, use norm.interval(0.95, loc=mu, scale=sigma) to request endpoints for an interval containing 95% of that normal distribution.

This is a distribution interval, not automatically a confidence interval for an unknown parameter estimated from data. A statistical confidence interval for a parameter requires an inferential model and an uncertainty calculation suited to the estimator; the norm.interval call alone does not provide that analysis. SciPy’s reference guide for the interval method describes endpoints containing a requested proportion of the distribution.

Check your 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 is from SciPy 0.13.0. Consult the documentation matching your installed release before relying on release-specific signatures or behavior. The meanings of density, cumulative probability, quantile, random variates, and a central distribution interval are the key distinctions when choosing among these methods.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.