[Numpy-discussion] Example of numpy cov() not correct?

Keith Goodman kwgoodman@gmail....
Wed Jul 30 09:04:55 CDT 2008


On Tue, Jul 29, 2008 at 9:10 PM, Anthony Kong
<Anthony.Kong@macquarie.com> wrote:
> I am trying out the example here
> (http://www.scipy.org/Numpy_Example_List_With_Doc#cov)
>
>
>>>> from numpy import *
> ...
>>>> T = array([1.3, 4.5, 2.8, 3.9])
>>>> P = array([2.7, 8.7, 4.7, 8.2])
>>>> cov(T,P)
>
> The answer is supposed to be 3.9541666666666657
>
> The result I got is instead a cov matrix
> array([[ 1.97583333,  3.95416667],
>       [ 3.95416667,  8.22916667]])
> So, I just wanna confirm this particular example may be no longer
> correct.
>
> I am using python 2.4.3 with numpy 1.1.0 on MS win

It works for me (1.1 on GNU/Linux):

>> import numpy as np
>> T = np.array([1.3, 4.5, 2.8, 3.9])
>> P = np.array([2.7, 8.7, 4.7, 8.2])
>> np.cov(T,P)

array([[ 1.97583333,  3.95416667],
       [ 3.95416667,  8.22916667]])'


More information about the Numpy-discussion mailing list