Distributions
One of the main strengths of the scipy.stats
module is the great number of distributions coded, both continuous and discrete. The list is impressively large and has at least 80 continuous distributions and 10 discrete distributions.
One of the most common ways to employ these distributions is the generation of random numbers. We have been employing this technique to contaminate our images with noise, for example:
>>> import scipy.misc >>> from scipy.stats import signaltonoise >>> from scipy.stats import norm # Gaussian distribution >>> lena=scipy.misc.lena().astype(float) >>> lena+= norm.rvs(loc=0,scale=16,size=lena.shape) >>> signaltonoise(lena,axis=None)
The output is shown as follows:
array(2.459233897516763)
Let's see the SciPy way of handling distributions. First, a random variable class is created (in SciPy there is the rv_continuous
class for continuous random variables and the rv_discrete
class for the discrete...