There seems to be numpy.corrcoef that calculates correlation coefficients if required. However, its interface is different from Octave / Matlab corr .
First of all, by default, the function treats rows as variables, with columns being cases. To mimic the behavior of Octave / Matlab, you can pass a flag that overrides this.
Also, according to this answer , the numpy.cov function (which I assume uses corrcoef ) returns a 2x2 matrix, each of which contains a specific covariance:
cov(a,a) cov(a,b) cov(a,b) cov(b,b)
As he points out, the element [0][1] is what you want for cov(a,b) . Thus, perhaps something like this will work:
for i in range(25): c2[i] = numpy.corrcoef(a[:,i], b, rowvar=0)[0][1]
For reference, here are some excerpts from the two functions you tried. It seems like they are doing completely different things.
Octave:
- Function file: corr (x, y)
Calculate the matrix of correlation coefficients.
If each row x and y is an observation, and each column is a variable, then the (i, j) th input corr (x, y) is the correlation between the i-th variable in x and the j-th variable in y.
corr (x,y) = cov (x,y) / (std (x) * std (y))
If called with one argument, calculate corr (x, x), then the correlation between the columns is from x.
And Numpy:
numpy.correlate (a, v, mode = 'valid', old_behavior = False) [source]
Cross-correlation of two one-dimensional sequences.
This function calculates the correlation, as is usually defined in the signal processing texts:
z[k] = sum_n a[n] * conj(v[n+k])
with a and v sequences at zero filling, and conj is conjugate.