In NumPy, We can compute pearson product-moment correlation coefficients of two given arrays with the help of numpy.corrcoef() function.
In this function, we will pass arrays as a parameter and it will return the pearson product-moment correlation coefficients of two given arrays.
Syntax: numpy.corrcoef(x, y=None, rowvar=True, bias=, ddof=)
Return: Pearson product-moment correlation coefficients
Let’s see an example:
Example 1:
Python
import numpy as np
array1 = np.array([ 0 , 1 , 2 ])
array2 = np.array([ 3 , 4 , 5 ])
rslt = np.corrcoef(array1, array2)
print (rslt)
|
Output
[[1. 1.]
[1. 1.]]
Example 2:
Python
import numpy as np
array1 = np.array([ 2 , 4 , 8 ])
array2 = np.array([ 3 , 2 , 1 ])
rslt2 = np.corrcoef(array1, array2)
print (rslt2)
|
Output
[[ 1. -0.98198051]
[-0.98198051 1. ]]