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

Wed Jul 30 10:49:10 CDT 2008

```If you read the cov function documentation you'll see that if a second vector is given, it joins the 2 into one matrix and calculate the covariance of it. In your case, you are looking for the off-diagonal elements.

-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Keith Goodman
נשלח: ד 30-יולי-08 17:04
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] Example of numpy cov() not correct?

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]])'
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3587 bytes
Desc: not available