def corr2_coeff(A, B):
    A_mA = A - A.mean(1)[:, (None)]
B_mB = B - B.mean(1)[:, (None)]
ssA = (A_mA ** 2).sum(1)
ssB = (B_mB ** 2).sum(1)
return np.dot(A_mA, B_mB.T) / np.sqrt(np.dot(ssA[:, (None)], ssB[None]))
Computing the correlation coefficient between two multi-dimensional arrays