
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - stats.norm.cdf() Function
scipy.stats.norm.cdf() is a function in the SciPy library that calculates the cumulative distribution function (CDF) of a normal distribution for a given value x. The function belongs to the SciPy stats module where loc represents the mean () and scale is the standard deviation ().
The cumulative distribution function is given by the integral of the probability density function (PDF) from negative infinity to x, mathematically expressed as follows −
F(x) = ⁄√2π ∫-∞x e- ⁄ (t - μ)2 / 2σ2 dt
Syntax
The syntax for using scipy.stats.norm.cdf() is as follows −
scipy.stats.norm.cdf(x, loc=0, scale=1)
Parameters
Following are the parameters of the function scipy.stats.norm.cdf() which is used to calculate the cumulative distribution function (CDF) −
- x: The input value where the CDF is evaluated.
- loc (optional): The mean () of the normal distribution. Default value is 0.
- scale (optional): The standard deviation () of the normal distribution. Default value is 1.
Return Value
This function returns the cumulative probability by indicating the likelihood of obtaining a value less than or equal to x from the normal distribution.
Computing CDF for Standard Normal Distribution
The cumulative distribution function (CDF) of a normal distribution gives the probability that a random variable X will take a value less than or equal to a given value x. In the standard normal distribution where mean () = 0 and standard deviation () = 1, the CDF tells us how much of the distribution lies to the left of x.
In this example we will compute the CDF at x = 1 using the scipy.stats.norm.cdf() function −
import numpy as np from scipy.stats import norm # Define parameters for standard normal distribution x = 1 mean = 0 std_dev = 1 # Compute the CDF cdf_value = norm.cdf(x, loc=mean, scale=std_dev) # Print the result print(f"CDF value at x={x}: {cdf_value}")
Following is the output of the standard normal distribution CDF computed using the function scipy.stats.norm.cdf() −
CDF value at x=1: 0.8413447460685429
Computing Probability of a Value Less X
In real-world applications the normal distributions often have different means and standard deviations. The CDF can be used to calculate the probability that a random variable X will be less than or equal to a specific value.
Here in this example, we compute the probability that X 50 in a normal distribution with mean = 40 and standard deviation = 10 using scipy.stats.norm.cdf() −
import numpy as np from scipy.stats import norm # Define parameters for a normal distribution x = 50 mean = 40 std_dev = 10 # Compute the CDF cdf_value = norm.cdf(x, loc=mean, scale=std_dev) # Print the result print(f"Probability that X {x}: {cdf_value}")
Following is the output of the CDF computation −
Probability that X 50: 0.8413447460685429
Plotting the CDF Curve for a Normal Distribution
The cumulative distribution function (CDF) helps visualize the probability of obtaining values up to a given x in a normal distribution. The CDF curve starts from 0 and asymptotically approaches 1 as x increases.
Below is the example in which we plot the CDF of a normal distribution with mean = 0 and standard deviation = 1 using the scipy.stats.norm.cdf() function −
import matplotlib.pyplot as plt from scipy.stats import norm import numpy as np # Define the range of x values x_values = np.linspace(-5, 5, 100) # Compute the CDF for each x value cdf_values = norm.cdf(x_values, loc=0, scale=1) # Plot the CDF plt.plot(x_values, cdf_values, label="Standard Normal CDF", color="red") plt.title("Cumulative Distribution Function (CDF)") plt.xlabel("x") plt.ylabel("Cumulative Probability") plt.legend() plt.grid(True) plt.show()
Following is the output of the CDF computation visualized as a cumulative probability curve −
