Normal Distribution
The Normal Distribution (also known as the Gaussian Distribution, named after mathematician Carl Friedrich Gauss) is one of the most commonly used probability distributions.
It models many natural phenomena such as IQ scores, heartbeat rates, and more.
Creating a Normal Distribution in Python
You can use the random.normal() method from NumPy to generate a normal distribution.
This method takes three main parameters:
loc: The mean (center) of the distribution.
scale: The standard deviation (controls the spread or width of the bell curve).
size: The shape of the output array.
Program:
Generate a 2x3 normal distribution array (default mean=0, std=1):
from numpy import random
x = random.normal(size=(2, 3))
print(x)
Output:
[[ 0.234 -0.875 0.491]
[-1.293 0.732 0.084]]
Note: Your output will be different every time because it’s random.
Program:
Generate a normal distribution with a mean of 1 and standard deviation of 2:
from numpy import random
x = random.normal(loc=1, scale=2, size=(2, 3))
print(x)
Output:
Visualizing a Normal Distribution
Here's how to visualize a normal distribution using Seaborn and Matplotlib:
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns
sns.displot(random.normal(size=1000), kind="kde")
plt.show()