basic statistics in python
John Gorman
jdgorman at ieee.org
Thu Mar 14 00:45:35 EST 2002
Doug,
Another consideration is using the MLab module and Numeric. MLab
emulates several Matlab function calls including "cov" (which doesn't
have a docstring, by the way, but here's Matlab's definition of cov():
"""COV Covariance matrix.
COV(X), if X is a vector, returns the variance. For matrices,
where each row is an observation, and each column a variable,
COV(X) is the covariance matrix....
"""
Anyway, you could write your own python-based code, but the cov()
function is likely to be more efficient for large arrays. Here's an
example using the scipy module (which contains Numeric and MLab):
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import scipy
>>> # generate a vector of std nrml rv's
>>> v = scipy.normal(0,1,100)
>>> # cov returns the variance if its argument is a vector
>>> # rather than a matrix
>>> sig_v = scipy.sqrt(scipy.cov(v))
>>> print sig_v
0.97295502908
I haven't peeked under the hood with scipy.normal, but I'm assuming
they're using something similar to the Box-Muller algorithm... Perhaps I
ended up with a "bad seed" here (expecting sig_v = 1) ;^). Hopefully
you get the picture... ;^)
Finally, if you want access to other statistical routines there are
some python based modules floating around including Scientific Python
and Gary Strangman has stats.py at:
http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html
Cheers,
John Gorman
Fernando Pérez wrote:
> dsavitsk wrote:
>
>
>>i found this
>>http://starship.python.net/crew/hinsen/ScientificPythonManual/
>>but it seems to be unix only and i am on win32. as far as standard
>>
>
> you can probably get the stuff you want running under win. I'd be very
> surprised if all of Konrad's code was tied to unix (though I can't tell for
> sure, I use it under unix).
>
>
>>There seems to be some stuff in scipy, but i am having trouble geting
>>through the docs. also, do i want to look at numpy?
>>
>
> Scipy is early and still a bit rough to install, but fabulous. And yes, you
> NEED numpy for anything numerical in python above the toy level. Both
> konrad's libs and scipy are numpy based anyway.
>
> cheers,
>
> f
>
More information about the Python-list
mailing list