Skip to main content

Introduction to Python Normal Distribution

Python Normal Distribution

The normal distribution, also known as the Gaussian distribution, is a probability distribution that is symmetric and bell-shaped.

It is one of the most commonly encountered distributions in statistics and probability theory.

In a normal distribution, the data cluster around the mean value, with fewer observations towards the tails of the distribution.

The probability density function (PDF) of a normal distribution is given by the following formula:

f(x) = (1 / (σ * sqrt(2π))) * exp(-((x - μ)^2) / (2σ^2))

Where:

  • μ (mu) represents the mean of the distribution.
  • σ (sigma) represents the standard deviation of the distribution.
  • π (pi) is a mathematical constant (approximately 3.14159).
  • exp() is the exponential function.
  • sqrt() is the square root function.

In Python, you can generate random numbers that follow a normal distribution using the numpy.random.normal() function from the NumPy library.

As an example:

import numpy as np

# Generate random numbers from a normal distribution
mu = 0 # Mean
sigma = 1 # Standard deviation
size = 1000 # Number of random numbers to generate

random_numbers = np.random.normal(mu, sigma, size)

In this example:

  • The np.random.normal(mu, sigma, size) generates an array of 1000 random numbers from a normal distribution with a mean of 0 and a standard deviation of 1.
  • You can adjust the values of mu and sigma to control the mean and standard deviation of the distribution, respectively.
  • The resulting array random_numbers will contain the generated random numbers.