@@ -276,9 +276,8 @@ def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none,
276
276
277
277
def corrcoef (* args ):
278
278
"""
279
-
280
279
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 .
282
281
283
282
corrcoef(x,y) where x and y are vectors returns the matrix or
284
283
correlation coefficients for x and y.
@@ -287,9 +286,10 @@ def corrcoef(*args):
287
286
288
287
The correlation matrix is defined from the covariance matrix C as
289
288
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])
291
290
"""
292
291
292
+
293
293
if len (args )== 2 :
294
294
X = transpose (array ([args [0 ]]+ [args [1 ]]))
295
295
elif len (args )== 1 :
@@ -299,8 +299,18 @@ def corrcoef(*args):
299
299
300
300
301
301
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
+
304
314
r = divide (C ,denom )
305
315
try : return r .real
306
316
except AttributeError : return r
@@ -1140,7 +1150,7 @@ def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
1140
1150
Most of this module requires Numerical Python or is meant to be used with it.
1141
1151
See http://www.pfdubois.com/numpy for details.
1142
1152
1143
- Copyright (c) 2001-2004, Fernando Pérez . <Fernando.Perez@colorado.edu>
1153
+ Copyright (c) 2001-2004, Fernando Perez . <Fernando.Perez@colorado.edu>
1144
1154
All rights reserved.
1145
1155
1146
1156
This license was generated from the BSD license template as found in:
0 commit comments