15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SciPy Reference Guide, Release 0.8.dev<br />

Note how, by virtue of how matrix analytic functions are defined, the Bessel function has acted on the matrix eigenvalues.<br />

1.9 Statistics<br />

1.9.1 Introduction<br />

SciPy has a tremendous number of basic statistics routines with more easily added by the end user (if you create<br />

one please contribute it). All of the statistics functions are located in the sub-package <strong>scipy</strong>.stats and a fairly<br />

complete listing of these functions can be had using info(stats).<br />

Random Variables<br />

There are two general distribution classes that have been implemented for encapsulating continuous random variables<br />

and discrete random variables . Over 80 continuous random variables and 10 discrete random variables have been<br />

implemented using these classes. The list of the random variables available is in the docstring for the stats subpackage.<br />

Note: The following is work in progress<br />

1.9.2 Distributions<br />

First some imports<br />

>>> import numpy as np<br />

>>> from <strong>scipy</strong> import stats<br />

>>> import warnings<br />

>>> warnings.simplefilter(’ignore’, DeprecationWarning)<br />

We can obtain the list of available distribution through introspection:<br />

>>> dist_continu = [d for d in dir(stats) if<br />

... isinstance(getattr(stats,d), stats.rv_continuous)]<br />

>>> dist_discrete = [d for d in dir(stats) if<br />

... isinstance(getattr(stats,d), stats.rv_discrete)]<br />

>>> print ’number of continuous distributions:’, len(dist_continu)<br />

number of continuous distributions: 84<br />

>>> print ’number of discrete distributions: ’, len(dist_discrete)<br />

number of discrete distributions: 12<br />

Distributions can be used in one of two ways, either by passing all distribution parameters to each method call or by<br />

freezing the parameters for the instance of the distribution. As an example, we can get the median of the distribution<br />

by using the percent point function, ppf, which is the inverse of the cdf:<br />

>>> print stats.nct.ppf(0.5, 10, 2.5)<br />

2.56880722561<br />

>>> my_nct = stats.nct(10, 2.5)<br />

>>> print my_nct.ppf(0.5)<br />

2.56880722561<br />

help(stats.nct) prints the complete docstring of the distribution. Instead we can print just some basic information:<br />

1.9. Statistics 49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!