Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
numpy.random.standard_exponential() in Python
Next article icon

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
importnumpyasnprandom_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
importnumpyasnpimportmatplotlib.pyplotaspltimportseabornassnsscale=2size=1000data=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.



Improve
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp