python-scipyHow do I use Python Scipy to generate an exponential distribution?
Scipy is a powerful python library for scientific computing. It provides a wide range of functions for generating and manipulating probability distributions. To generate an exponential distribution using Scipy, the scipy.stats.expon
function can be used.
Example code
import scipy.stats
x = scipy.stats.expon.rvs(size=10)
print(x)
Example output:
[1.97790379 0.96668961 0.37204524 0.18509819 0.14698962 1.78867799
0.73548481 0.30222099 0.73564717 0.61254917]
Code explanation
import scipy.stats
: imports thescipy.stats
modulescipy.stats.expon.rvs(size=10)
: generates 10 random variables from an exponential distributionprint(x)
: prints the generated random variables
Helpful links
More of Python Scipy
- How can I check if a certain version of Python is compatible with SciPy?
- How do I check the version of Python Scipy I am using?
- How can I use RK45 with Python and SciPy?
- How can I use Python SciPy to fit a model?
- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How do I check the version of Python SciPy I'm using?
- How do I create a zero matrix using Python and Numpy?
- How can I use the x.shape function in Python Numpy?
- How do I create a numpy array of zeros using Python?
See more codes...