A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/numpy-random-exponential-in-python/ below:

Exponential Distribution in NumPy - GeeksforGeeks

Exponential Distribution in NumPy

Last Updated : 23 Apr, 2025

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)

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

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.



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