correlation coefficient in python code example
Example 1: correlation coefficient python numpy example
>>> r = np.corrcoef(x, y)
>>> r
array([[1. , 0.75864029],
[0.75864029, 1. ]])
>>> r[0, 1]
0.7586402890911867
>>> r[1, 0]
0.7586402890911869
Example 2: python pearson correlation
import scipy
# x and y are numpy array with shape (N,)
coeff, _ = scipy.stats.pearsonr(x, y)