[SciPy-User] calculating covariances fast (and accurate)

Sturla Molden sturla at molden.no
Thu Jul 8 20:08:32 EDT 2010


Sturla Molden skrev:
> One important lesson from this: it does not help to write a function 
> like cov(X) in C, when we have access to optimized BLAS from Python. So 
> let this serve as a warning against using C istead of Python.
>   

After plowing though numpy svn, I located np.dot here:

http://svn.scipy.org/svn/numpy/trunk/numpy/ma/extras.py

It seems numpy.cov is written in Python too. But it uses np.dot instead 
of dgemm (why is that less efficient?), deals with masked arrays, and 
forms more temporary arrays. That's why it's slower. The biggest 
contribution is probably dgemm vs. np.dot.

And np.cov does not correct for rounding errors (which I think it should).

Sturla



More information about the SciPy-User mailing list