简体   繁体   中英

Trying to calculate autocorrelation coefficient with function

I am trying to replicate this autocorrelation formula, where T is number of samples and k is number of lags.

自相关公式

The autocorrelation for the first element is 1.0 per definition. For the remaining elements we use a list comprehension (please note that the formula in the questions assumes indexing from 1 to T whereas python arrays are 0 based):

mean = np.mean(x)    
denominator = np.sum((x-mean)**2)
[1.0] + [np.sum((x[j:]-mean) * (x[:-j]-mean)) / denominator for j in range(1, len(x))]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM