
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy Arrays
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy Creating and Manipulating Arrays
- NumPy - Array Creation Routines
- NumPy - Array Manipulation
- NumPy - Array from Existing Data
- NumPy - Array From Numerical Ranges
- NumPy - Iterating Over Array
- NumPy - Reshaping Arrays
- NumPy - Concatenating Arrays
- NumPy - Stacking Arrays
- NumPy - Splitting Arrays
- NumPy - Flattening Arrays
- NumPy - Transposing Arrays
- NumPy Indexing & Slicing
- NumPy - Indexing & Slicing
- NumPy - Indexing
- NumPy - Slicing
- NumPy - Advanced Indexing
- NumPy - Fancy Indexing
- NumPy - Field Access
- NumPy - Slicing with Boolean Arrays
- NumPy Array Attributes & Operations
- NumPy - Array Attributes
- NumPy - Array Shape
- NumPy - Array Size
- NumPy - Array Strides
- NumPy - Array Itemsize
- NumPy - Broadcasting
- NumPy - Arithmetic Operations
- NumPy - Array Addition
- NumPy - Array Subtraction
- NumPy - Array Multiplication
- NumPy - Array Division
- NumPy Advanced Array Operations
- NumPy - Swapping Axes of Arrays
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Element-wise Array Comparisons
- NumPy - Filtering Arrays
- NumPy - Joining Arrays
- NumPy - Sort, Search & Counting Functions
- NumPy - Searching Arrays
- NumPy - Union of Arrays
- NumPy - Finding Unique Rows
- NumPy - Creating Datetime Arrays
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy Sorting and Advanced Manipulation
- NumPy - Sorting Arrays
- NumPy - Sorting along an axis
- NumPy - Sorting with Fancy Indexing
- NumPy - Structured Arrays
- NumPy - Creating Structured Arrays
- NumPy - Manipulating Structured Arrays
- NumPy - Record Arrays
- Numpy - Loading Arrays
- Numpy - Saving Arrays
- NumPy - Append Values to an Array
- NumPy - Swap Columns of Array
- NumPy - Insert Axes to an Array
- NumPy Handling Missing Data
- NumPy - Handling Missing Data
- NumPy - Identifying Missing Values
- NumPy - Removing Missing Data
- NumPy - Imputing Missing Data
- NumPy Performance Optimization
- NumPy - Performance Optimization with Arrays
- NumPy - Vectorization with Arrays
- NumPy - Memory Layout of Arrays
- Numpy Linear Algebra
- NumPy - Linear Algebra
- NumPy - Matrix Library
- NumPy - Matrix Addition
- NumPy - Matrix Subtraction
- NumPy - Matrix Multiplication
- NumPy - Element-wise Matrix Operations
- NumPy - Dot Product
- NumPy - Matrix Inversion
- NumPy - Determinant Calculation
- NumPy - Eigenvalues
- NumPy - Eigenvectors
- NumPy - Singular Value Decomposition
- NumPy - Solving Linear Equations
- NumPy - Matrix Norms
- NumPy Element-wise Matrix Operations
- NumPy - Sum
- NumPy - Mean
- NumPy - Median
- NumPy - Min
- NumPy - Max
- NumPy Set Operations
- NumPy - Unique Elements
- NumPy - Intersection
- NumPy - Union
- NumPy - Difference
- NumPy Random Number Generation
- NumPy - Random Generator
- NumPy - Permutations & Shuffling
- NumPy - Uniform distribution
- NumPy - Normal distribution
- NumPy - Binomial distribution
- NumPy - Poisson distribution
- NumPy - Exponential distribution
- NumPy - Rayleigh Distribution
- NumPy - Logistic Distribution
- NumPy - Pareto Distribution
- NumPy - Visualize Distributions With Sea born
- NumPy - Matplotlib
- NumPy - Multinomial Distribution
- NumPy - Chi Square Distribution
- NumPy - Zipf Distribution
- NumPy File Input & Output
- NumPy - I/O with NumPy
- NumPy - Reading Data from Files
- NumPy - Writing Data to Files
- NumPy - File Formats Supported
- NumPy Mathematical Functions
- NumPy - Mathematical Functions
- NumPy - Trigonometric functions
- NumPy - Exponential Functions
- NumPy - Logarithmic Functions
- NumPy - Hyperbolic functions
- NumPy - Rounding functions
- NumPy Fourier Transforms
- NumPy - Discrete Fourier Transform (DFT)
- NumPy - Fast Fourier Transform (FFT)
- NumPy - Inverse Fourier Transform
- NumPy - Fourier Series and Transforms
- NumPy - Signal Processing Applications
- NumPy - Convolution
- NumPy Polynomials
- NumPy - Polynomial Representation
- NumPy - Polynomial Operations
- NumPy - Finding Roots of Polynomials
- NumPy - Evaluating Polynomials
- NumPy Statistics
- NumPy - Statistical Functions
- NumPy - Descriptive Statistics
- NumPy Datetime
- NumPy - Basics of Date and Time
- NumPy - Representing Date & Time
- NumPy - Date & Time Arithmetic
- NumPy - Indexing with Datetime
- NumPy - Time Zone Handling
- NumPy - Time Series Analysis
- NumPy - Working with Time Deltas
- NumPy - Handling Leap Seconds
- NumPy - Vectorized Operations with Datetimes
- NumPy ufunc
- NumPy - ufunc Introduction
- NumPy - Creating Universal Functions (ufunc)
- NumPy - Arithmetic Universal Function (ufunc)
- NumPy - Rounding Decimal ufunc
- NumPy - Logarithmic Universal Function (ufunc)
- NumPy - Summation Universal Function (ufunc)
- NumPy - Product Universal Function (ufunc)
- NumPy - Difference Universal Function (ufunc)
- NumPy - Finding LCM with ufunc
- NumPy - ufunc Finding GCD
- NumPy - ufunc Trigonometric
- NumPy - Hyperbolic ufunc
- NumPy - Set Operations ufunc
- NumPy Useful Resources
- NumPy - Quick Guide
- NumPy - Cheatsheet
- NumPy - Useful Resources
- NumPy - Discussion
- NumPy Compiler
NumPy - Normal Distribution
What is a Normal Distribution?
A normal distribution, also known as the Gaussian distribution, is a continuous probability distribution that is symmetric around its mean, indicating that data near the mean are more frequent in occurrence than data far from the mean.
The shape of the normal distribution is described by its mean () and standard deviation (). The mean determines the center of the distribution, while the standard deviation controls the spread of the data.
Normal Distributions in NumPy
NumPy provides the numpy.random.normal() function to generate samples from a normal distribution. This function allows you to specify the mean, standard deviation, and size of the generated samples.
Example
In this example, we generate 10 random samples from a normal distribution with a mean of 0 and a standard deviation of 1 −
import numpy as np # Generate 10 random samples from a normal distribution with mean 0 and standard deviation 1 samples = np.random.normal(0, 1, 10) print("Random samples from normal distribution:", samples)
Following is the output obtained −
Random samples from normal distribution: [ 1.45958315 -1.47376803 0.86885907 0.28076705 -2.16173553 -0.43457503 0.47706858 0.65894456 0.56166159 -0.71025105]
Visualizing Normal Distributions
Visualizing normal distributions helps to understand their properties better. We can use libraries such as Matplotlib to create histograms that display the distribution of generated samples.
Example
In the following example, we are generating 1000 random samples from a normal distribution with mean 0 and standard deviation 1 and then create a histogram to visualize this distribution −
import numpy as np import matplotlib.pyplot as plt # Generate 1000 random samples from a normal distribution with mean 0 and standard deviation 1 samples = np.random.normal(0, 1, 1000) # Create a histogram to visualize the distribution plt.hist(samples, bins=30, edgecolor='black', density=True) # Plot the probability density function (PDF) x = np.linspace(-4, 4, 1000) pdf = 1/(np.sqrt(2 * np.pi)) * np.exp(-x**2 / 2) plt.plot(x, pdf, 'r', linewidth=2) plt.title('Normal Distribution') plt.xlabel('Value') plt.ylabel('Frequency') plt.show()
The histogram shows that the samples follow a bell-shaped curve, which is characteristic of a normal distribution. The red line represents the theoretical probability density function (PDF) of the normal distribution −

Applications of Normal Distributions
Normal distributions are used in various fields, including statistics, finance, engineering, and the natural and social sciences. Here are a few practical applications:
- Statistical Analysis: Many statistical tests and methods assume that the data follow a normal distribution.
- Quality Control: In manufacturing, normal distributions are used to monitor and control processes.
- Finance: Asset returns are often modeled using normal distributions.
Generating Multivariate Normal Distributions
NumPy also allows generating samples from a multivariate normal distribution using the numpy.random.multivariate_normal() function. This function generates samples from a multivariate normal distribution with a specified mean vector and covariance matrix.
Example
In this example, we generate 1000 random samples from a multivariate normal distribution with a specified mean vector and covariance matrix −
import numpy as np # Define the mean vector and covariance matrix mean = [0, 0] cov = [[1, 0.5], [0.5, 1]] # Generate 1000 random samples from a multivariate normal distribution samples = np.random.multivariate_normal(mean, cov, 1000) print("Random samples from multivariate normal distribution:", samples[:5])
The output obtained is as shown below −
Random samples from multivariate normal distribution: [[-0.13543463 1.3100422 ] [-1.46447528 -0.42485422] [ 0.31941286 -0.33503219] [ 0.86726151 1.43161159] [ 0.12539345 -1.72856329]]
Properties of Normal Distributions
Normal distributions have several key properties, they are −
- Symmetry: The normal distribution is symmetric around the mean.
- Mean, Median, and Mode: In a normal distribution, the mean, median, and mode are all equal.
- Empirical Rule: Approximately 68% of the data falls within one standard deviation of the mean, 95% within two standard deviations, and 99.7% within three standard deviations.
Standard Normal Distribution
The standard normal distribution is a special case of the normal distribution with a mean of 0 and a standard deviation of 1. It is often used as a reference distribution. You can generate samples from a standard normal distribution using the numpy.random.standard_normal() function.
Example
In this example, we generate 10 random samples from a standard normal distribution −
import numpy as np # Generate 10 random samples from a standard normal distribution samples = np.random.standard_normal(10) print("Random samples from standard normal distribution:", samples)
The result produced is as follows −
Random samples from standard normal distribution: [ 0.41271088 -0.06102183 -0.48159376 0.63379932 -0.41831826 -0.67104197 0.2019988 0.52954154 -0.39241029 -0.19626287]
Seeding for Reproducibility
To ensure reproducibility, you can set a specific seed before generating normal distributions. This ensures that the same sequence of random numbers is generated each time you run the code.
Example
By setting the seed, you ensure that the random generation produces the same result every time the code is executed as shown in the example below −
import numpy as np # Set the seed for reproducibility np.random.seed(42) # Generate 10 random samples from a normal distribution with mean 0 and standard deviation 1 samples = np.random.normal(0, 1, 10) print("Random samples with seed 42:", samples)
We get the output as shown below −
Random samples with seed 42: [ 0.49671415 -0.1382643 0.64768854 1.52302986 -0.23415337 -0.23413696 1.57921282 0.76743473 -0.46947439 0.54256004]