The NumPy Exponential Distribution is a probability distribution that describes the time between events in a Poisson process, where events occur continuously and independently at a constant average rate. It is a continuous distribution that takes on non-negative values and has a single parameter, lambda, which represents the rate of the Poisson process.
The probability density function (PDF) of the exponential distribution is given by:
where λ is the rate parameter and x is the random variable.
The cumulative distribution function (CDF) of the exponential distribution is given by:
The NumPy implementation of the exponential distribution provides functions for generating random numbers from the distribution, as well as calculating the PDF and CDF for a given set of parameters.
To generate a random sample of size 1000 from an exponential distribution with a rate parameter of 0.5, we can use the numpy.random.exponential()
function:
<pre><code>import numpy as np
# Generate a random sample of size 1000 from an exponential distribution with a rate parameter of 0.5
sample = np.random.exponential(scale=1/0.5, size=1000)
print(sample)</code></pre>
The scale
parameter is the inverse of the rate parameter, so we pass 1/0.5
as the scale to achieve a rate of 0.5.
To calculate the PDF of the exponential distribution for a given set of parameters, we can use the numpy.exp()
function:
<pre><code>import numpy as np
# Calculate the PDF of the exponential distribution for x=1, lambda=0.5
x = 1
lmbda = 0.5
pdf = lmbda * np.exp(-lmbda * x)
print(pdf)</code></pre>
To calculate the CDF of the exponential distribution for a given set of parameters, we can use the numpy.exp()
and numpy.cumsum()
functions:
<pre><code>import numpy as np
# Calculate the CDF of the exponential distribution for x=1, lambda=0.5
x = 1
lmbda = 0.5
cdf = 1 - np.exp(-lmbda * x)
print(cdf)</code></pre>