Last Updated : 23 Apr, 2025
The Normal Distribution also known as the Gaussian Distribution is one of the most important distributions in statistics and data science. It is widely used to model real-world phenomena such as IQ scores, heart rates, test results and many other naturally occurring events.
numpy.random.normal()
Method
In Python's NumPy library we can generate random numbers following a Normal Distribution using the numpy.random.normal()
method. It has three key parameters:
Example 1: Generate a Single Random Numbernumpy.random.normal(loc=0.0, scale=1.0, size=None)
To generate a single random number from a default Normal Distribution (loc=0
, scale=1
):
import numpy as np
random_number = np.random.normal()
print(random_number)
Output:
Example 2: Generate an Array of Random Numbers0.013289272641035141
To generate multiple random numbers
Python
random_numbers = np.random.normal(size=5)
print(random_numbers)
Output:
Visualizing the Normal Distribution[ 1.44819595 0.90517495 -0.75923069 0.50357022 -0.34776612]
Visualizing the generated numbers helps in understanding their behavior. Below is an example of plotting a histogram of random numbers generated using numpy.random.normal
.
import numpy as np
import matplotlib.pyplot as plt
data = np.random.normal(loc=0, scale=1, size=1000)
plt.hist(data, bins=30, edgecolor='black', density=True)
pdf = norm.pdf(x, loc=loc, scale=scale)
plt.plot(x, pdf, color='red', label='Theoretical PDF')
plt.title("Normal Distribution")
plt.xlabel("Value")
plt.ylabel("Density")
plt.grid(True)
plt.show()
Output:
Normal DistributionThe histogram represents the frequency of the generated numbers and the curve shows the theoretical pattern for comparison. The curve of a Normal Distribution is also known as the Bell Curve because of the bell-shaped curve.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4