[Numpy-discussion] Cross-covariance function

Pierre Haessig pierre.haessig at crans.org
Fri Jan 20 13:04:26 EST 2012


Le 20/01/2012 16:30, Sturla Molden a écrit :
> Often we just want the upper-right p x p quadrant.
Thanks for the explanation.
If I understood it correctly, you're interested in the
*cross*-covariance block of the matrix (and now I understand better
Elliot's message). Actually, I thought that was the behavior of the
np.cor function ! But you're right it's not ! [source code] The seconde
'y' argument just gets concatenated with the first one 'm'.

I would go further and ask why it so. People around may have use cases
in mind, because I have not.
Otherwise, I feel that the default behavior of cov when called with two
arguments should be what Sturla and Elliot just described.

Best,
Pierre

(that is something like this :

def cov(X, Y=None):
    if Y is None:
        Y = X
    else:
          assert Y.shape == X.shape # or something like that
    # [...jumping to the end of the existing code...]   
    if not rowvar:
        return (dot(X.T, Y.conj()) / fact).squeeze()
    else:
        return (dot(X, Y.T.conj()) / fact).squeeze()
)

[source code]
https://github.com/numpy/numpy/blob/master/numpy/lib/function_base.py



More information about the NumPy-Discussion mailing list