@@ -276,9 +276,8 @@ def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none,
276276
277277def corrcoef (* args ):
278278 """
279-
280279 corrcoef(X) where X is a matrix returns a matrix of correlation
281- coefficients for each row of X .
280+ coefficients for each numrows observations and numcols variables .
282281
283282 corrcoef(x,y) where x and y are vectors returns the matrix or
284283 correlation coefficients for x and y.
@@ -287,9 +286,10 @@ def corrcoef(*args):
287286
288287 The correlation matrix is defined from the covariance matrix C as
289288
290- r(i,j) = C[i,j] / (C[i,i]*C[j,j])
289+ r(i,j) = C[i,j] / sqrt (C[i,i]*C[j,j])
291290 """
292291
292+
293293 if len (args )== 2 :
294294 X = transpose (array ([args [0 ]]+ [args [1 ]]))
295295 elif len (args )== 1 :
@@ -299,8 +299,18 @@ def corrcoef(*args):
299299
300300
301301 C = cov (X )
302- d = resize (diagonal (C ), (2 ,1 ))
303- denom = sqrt (matrixmultiply (d ,transpose (d )))
302+
303+ if len (args )== 2 :
304+ d = resize (diagonal (C ), (2 ,1 ))
305+ denom = sqrt (matrixmultiply (d ,transpose (d )))
306+ else :
307+ dc = diagonal (C )
308+ N = len (dc )
309+ shape = N ,N
310+ vi = resize (dc , shape )
311+ denom = sqrt (vi * transpose (vi )) # element wise multiplication
312+
313+
304314 r = divide (C ,denom )
305315 try : return r .real
306316 except AttributeError : return r
@@ -1140,7 +1150,7 @@ def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
11401150Most of this module requires Numerical Python or is meant to be used with it.
11411151See http://www.pfdubois.com/numpy for details.
11421152
1143- Copyright (c) 2001-2004, Fernando Pérez . <[email protected] > 1153+ Copyright (c) 2001-2004, Fernando Perez . <[email protected] > 11441154All rights reserved.
11451155
11461156This license was generated from the BSD license template as found in:
0 commit comments