python中数组之间的相关性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21923577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:52:32  来源:igfitidea点击:

correlation between arrays in python

pythonarraysvectorcorrelation

提问by user1681664

I have 2 arrays.

我有 2 个数组。

 a1 = [1,2,4]
 a2 = [3,4,5]

how would I find the correlation between these 2 arrays using python.

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

In matlab, you would do:

在 matlab 中,你会这样做:

corr(a1,a2)

How to do this in python?

如何在python中做到这一点?

采纳答案by CT Zhu

You need numpy.corrcoef:

你需要numpy.corrcoef

In [8]:

np.corrcoef(a1,a2)
Out[8]:
array([[ 1.        ,  0.98198051],
       [ 0.98198051,  1.        ]])