Book Image

Learning SciPy for Numerical and Scientific Computing Second Edition - Second Edition

Book Image

Learning SciPy for Numerical and Scientific Computing Second Edition - Second Edition

Overview of this book

This book targets programmers and scientists who have basic Python knowledge and who are keen to perform scientific and numerical computations with SciPy.
Table of Contents (10 chapters)
9
Index

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...