exp#
- scipy.stats.exp(X, /)[source]#
Natural exponential of a random variable.
- Parameters:
- XContinuousDistribution
The random variable \(X\).
- Returns:
- YContinuousDistribution
A random variable \(Y = \exp(X)\).
Notes
Array API Standard Support
exphas support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
⛔
⛔
JAX
⛔
⛔
Dask
⛔
n/a
See Support for the array API standard for more information.
Examples
Suppose we have a normally distributed random variable \(X\):
>>> import numpy as np >>> from scipy import stats >>> X = stats.Normal()
We wish to have a lognormally distributed random variable \(Y\), a random variable whose natural logarithm is \(X\). If \(X\) is to be the natural logarithm of \(Y\), then we must take \(Y\) to be the natural exponential of \(X\).
>>> Y = stats.exp(X)
To demonstrate that
Xrepresents the logarithm ofY, we plot a normalized histogram of the logarithm of observations ofYagainst the PDF underlyingX.>>> import matplotlib.pyplot as plt >>> rng = np.random.default_rng() >>> y = Y.sample(shape=10000, rng=rng) >>> ax = plt.gca() >>> ax.hist(np.log(y), bins=50, density=True) >>> X.plot(ax=ax) >>> plt.legend(('PDF of `X`', 'histogram of `log(y)`')) >>> plt.show()