
- 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.pdf() Function
scipy.stats.norm.pdf() is a function in SciPy that computes the probability density function (PDF) of a normal (Gaussian) distribution at a given value x. This function is part of SciPys stats module where loc represents the mean () and scale is the standard deviation ().
The mathematical formula used to compute the probability density function is defined as follows −
f(x) = ⁄σ √2π e- ⁄ (x - μ)2 / 2σ2
Syntax
Following is the syntax of the function scipy.stats.norm.pdf() which computes the probability density function −
scipy.stats.norm.pdf(x, loc=0, scale=1)
Parameters
Below are the parameters of the scipy.stats.norm.pdf() function −
- x: The value at which the PDF 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
The scipy.stats.norm.pdf() function returns the probability density function value at x by representing the height of the normal distribution curve at that point.
Example of Standard Normal Distribution
The standard normal distribution is a special case of the normal distribution where the mean () is 0 and the standard deviation () is 1. It is used widely in statistics and probability theory.
In the standard normal distribution, the highest point occurs at x = 0 where the probability density is the largest.
In this example we will compute the probability density at x = 0 for the standard normal distribution by using the scipy.stats.norm.pdf() function −
import numpy as np from scipy.stats import norm # Define the parameters for the standard normal distribution x = 0 mean = 0 std_dev = 1 # Compute the PDF for standard normal distribution pdf_value = norm.pdf(x, loc=mean, scale=std_dev) # Print the result print(f"PDF value at x={x}: {pdf_value}")
Following is the output standard normal distribution computed by using the function scipy.stats.norm.pdf() −
PDF value at x=0: 0.3989422804014327
Example of Normal Distribution
The normal distribution is a continuous probability distribution characterized by its bell-shaped curve. It is defined by its mean () and standard deviation () where the mean determines the center of the distribution and the standard deviation controls the width. The normal distribution is widely used in statistics, finance, and various fields of science.
In this example, we will compute the probability density at a given point (x = 2) for a normal distribution with mean () = 3 and standard deviation () = 2 by using the scipy.stats.norm.pdf() function −
import numpy as np from scipy.stats import norm # Define the parameters for the normal distribution x = 2 mean = 3 std_dev = 2 # Compute the PDF for the normal distribution pdf_value = norm.pdf(x, loc=mean, scale=std_dev) # Print the result print(f"PDF value at x={x}: {pdf_value}")
Below is the output of the normal distribution computed by using the function scipy.stats.norm.pdf() −
PDF value at x=2: 0.17603266338214976
Example of Evaluating PDF for a Range of Values
In this example, we will compute the probability density function for a range of x values between -5 and 5 using the scipy.stats.norm.pdf() function and visualize the distribution curve −
import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm # Define the range of x values x_values = np.linspace(-5, 5, 100) # Compute the PDF for each x value pdf_values = norm.pdf(x_values, loc=0, scale=1) # Plot the PDF plt.plot(x_values, pdf_values, label="Standard Normal Distribution", color="blue") plt.title("PDF of Standard Normal Distribution") plt.xlabel("x") plt.ylabel("Probability Density") plt.legend() plt.grid(True) plt.show()
Following is the output of the standard normal distribution computed using the function scipy.stats.norm.pdf() visualized as a probability density curve −
