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.