Created
July 25, 2015 18:36
-
-
Save dengemann/65b5f67ec1ae51b1d9d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: [email protected] | |
# License: simplified BSD (3 clause) | |
# Note: code is based on scipy.stats.pearsonr | |
from scipy import stats | |
def compute_corr(x, y): | |
x = np.asarray(x) | |
y = np.asarray(y) | |
mx = x.mean(axis=-1) | |
my = y.mean(axis=-1) | |
xm, ym = x - mx[..., None], y - my[..., None] | |
r_num = np.add.reduce(xm * ym, axis=-1) | |
r_den = np.sqrt(stats.ss(xm, axis=-1) * stats.ss(ym, axis=-1)) | |
r = r_num / r_den | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ss has been removed from scipy, but it just did this:
Thanks for the function btw :)