scipy.stats.
log#
- scipy.stats.log(X, /)[source]#
- Natural logarithm of a non-negative random variable - Parameters:
- XContinuousDistribution
- The random variable \(X\) with positive support. 
 
- Returns:
- YContinuousDistribution
- A random variable \(Y = \exp(X)\). 
 
 - Examples - Suppose we have a gamma distributed random variable \(X\): - >>> import numpy as np >>> from scipy import stats >>> Gamma = stats.make_distribution(stats.gamma) >>> X = Gamma(a=1.0) - We wish to have a exp-gamma distributed random variable \(Y\), a random variable whose natural exponential is \(X\). If \(X\) is to be the natural exponential of \(Y\), then we must take \(Y\) to be the natural logarithm of \(X\). - >>> Y = stats.log(X) - To demonstrate that - Xrepresents the exponential of- Y, we plot a normalized histogram of the exponential of observations of- Yagainst the PDF underlying- X.- >>> import matplotlib.pyplot as plt >>> rng = np.random.default_rng() >>> y = Y.sample(shape=10000, rng=rng) >>> ax = plt.gca() >>> ax.hist(np.exp(y), bins=50, density=True) >>> X.plot(ax=ax) >>> plt.legend(('PDF of `X`', 'histogram of `exp(y)`')) >>> plt.show() 