如何解释numpy.correlate和numpy.corrcoef返回的值? [英] How to interpret the values returned by numpy.correlate and numpy.corrcoef?

查看:1366
本文介绍了如何解释numpy.correlate和numpy.corrcoef返回的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个1D数组,我想看看它们的相互关系.我应该在numpy中使用什么程序?我正在使用numpy.corrcoef(arrayA, arrayB)numpy.correlate(arrayA, arrayB),并且都给出了一些我无法理解或理解的结果.

I have two 1D arrays and I want to see their inter-relationships. What procedure should I use in numpy? I am using numpy.corrcoef(arrayA, arrayB) and numpy.correlate(arrayA, arrayB) and both are giving some results that I am not able to comprehend or understand.

有人可以阐明如何理解和解释这些数值结果吗?(最好是举个例子)?

Can somebody please shed light on how to understand and interpret those numerical results (preferably, using an example)?

推荐答案

numpy.correlate仅返回两个向量的互相关.

numpy.correlate simply returns the cross-correlation of two vectors.

如果您需要了解互相关,则从 http://en.wikipedia.org/wiki/Cross开始-相关性.

if you need to understand cross-correlation, then start with http://en.wikipedia.org/wiki/Cross-correlation.

通过查看自相关函数(一个与自身互相关的向量),可以看到一个很好的例子:

A good example might be seen by looking at the autocorrelation function (a vector cross-correlated with itself):

import numpy as np

# create a vector
vector = np.random.normal(0,1,size=1000) 

# insert a signal into vector
vector[::50]+=10

# perform cross-correlation for all data points
output = np.correlate(vector,vector,mode='full')

当两个数据集重叠时,这将返回具有最大值的梳齿/shah函数.由于这是自相关,因此在两个输入信号之间不会有滞后".因此,相关的最大值是vector.size-1.

This will return a comb/shah function with a maximum when both data sets are overlapping. As this is an autocorrelation there will be no "lag" between the two input signals. The maximum of the correlation is therefore vector.size-1.

如果仅需要重叠数据的相关值,则可以使用mode='valid'.

if you only want the value of the correlation for overlapping data, you can use mode='valid'.

这篇关于如何解释numpy.correlate和numpy.corrcoef返回的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆