[Numpy-discussion] Cross-covariance function

Pierre Haessig pierre.haessig@crans....
Fri Jan 27 04:09:53 CST 2012

Le 26/01/2012 19:19, josef.pktd@gmail.com a écrit :
> The discussion had this reversed, numpy matches the behavior of
> MATLAB, while R (statistics) only returns the cross covariance part as
> proposed.
I would also say that there was an attempt to match MATLAB behavior. 
However, there is big difference with numpy.cov because of the default 
value `rowvar` being True. Most softwares and textbooks I know consider 
that, in a 2D context, matrix rows are obvervations while columns are 
the variables.

Any idea why the "transposed" convention was selected in np.cov ?
(This question, I'm raising for informative purpose only... ;-) )

I also compared with octave to see how it works :
-- Function File: cov (X, Y)
Compute covariance.

If each row of X and Y is an observation and each column is a
variable, the (I, J)-th entry of `cov (X, Y)' is the covariance
between the I-th variable in X and the J-th variable in Y. If
called with one argument, compute `cov (X, X)'.

I like the clear tone of this description. But strangely enough, this a 
bit different from Matlab.

> If there is a new xcov, then I think there should also be a xcorrcoef.
> This case needs a different implementation than corrcoef, since the
> xcov doesn't contain the variances and they need to be calculated
> separately.
Adding xcorrcoeff as well would make sense. The use of the np.var when 
setting the `axis` and `̀̀ddof` arguments to appropriate values should the 
bring variances needed for the normalization.

In the end, if adding xcov is the path of least resistance, this may be 
the way to go. What do people think ?


More information about the NumPy-Discussion mailing list