python中数组之间的相关性

use*_*664 10 python arrays vector correlation

我有2个阵列.

 a1 = [1,2,4]
 a2 = [3,4,5]
Run Code Online (Sandbox Code Playgroud)

我如何使用python找到这两个数组之间的相关性.

在matlab中,你会这样做:

corr(a1,a2)
Run Code Online (Sandbox Code Playgroud)

如何在python中执行此操作?

CT *_*Zhu 22

你需要numpy.corrcoef:

In [8]:

np.corrcoef(a1,a2)
Out[8]:
array([[ 1.        ,  0.98198051],
       [ 0.98198051,  1.        ]])
Run Code Online (Sandbox Code Playgroud)