Skip to content

Instantly share code, notes, and snippets.

@JesseLivezey
Created March 10, 2016 01:14
Show Gist options
  • Save JesseLivezey/744c62e0442cb7d4c654 to your computer and use it in GitHub Desktop.
Save JesseLivezey/744c62e0442cb7d4c654 to your computer and use it in GitHub Desktop.
Calculate 1xn corrcoef
def corrcoef(X, Y):
"""
Return Pearson correlation coefficients between 1 and n variables.
Parameters
----------
X : (1 x dim) matrix, single voxel
Y : (n x dim) matrix, other voxels
"""
X_no_mean = X - X.mean(keepdims=True)
Y_no_mean = Y - Y.mean(axis=1, keepdims=True)
return X_no_mean.dot(Y_no_mean.T)/X.std(keepdims=True)/Y.std(axis=1, keepdims=True)/X.shape[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment