Open In App

Exponential Distribution in NumPy

Last Updated : 23 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Exponential Distribution is a fundamental concept in probability and statistics. It describe the time between events in a Poisson process where events occur continuously and independently at a constant average rate. You can generate random numbers which follow exponential Distribution using  numpy.random.exponential() method.

Syntax : numpy.random.exponential(scale=1.0, size=None)

  • scale : The inverse of the rate parameter (β=1/λ) which determines the spread of the distribution.
  • size : The shape of the returned array.

Example 1: Generate a Single Random Number

To generate a single random number from a default Exponential Distribution (scale=1):

Python
import numpy as np

random_number = np.random.exponential()
print(random_number)

Output:

0.008319485004465102

To generate multiple random numbers:

Python
random_numbers = np.random.exponential(size=5)
print(random_numbers)

Output:

[1.15900802 0.1997201 0.73995988 0.19688073 0.54198053]

Visualizing the Exponential Distribution

Visualizing the generated numbers helps in understanding their behavior. Below is an example of plotting a histogram of random numbers generated using numpy.random.exponential.

Python
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

scale = 2  
size = 1000  

data = np.random.exponential(scale=scale, size=size)

sns.histplot(data, bins=30, kde=True, color='orange', edgecolor='black')

plt.title(f"Exponential Distribution (Scale={scale})")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.grid(True)

plt.show()

Output:

Exponential-Distribution
Exponential Distribution

The above image shows an Exponential Distribution with a scale parameter of 2. The histogram represents simulated data while the orange curve depicts the theoretical distribution.



Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy