Hello I'd like to use this autocorrelation script, I found here:
https://stackoverflow.com/a/20463466/8238271
import numpy
def acf(series):
n = len(series)
data = numpy.asarray(series)
mean = numpy.mean(data)
c0 = numpy.sum((data - mean) ** 2) / float(n)
def r(h):
acf_lag = ((data[:n - h] - mean) * (data[h:] - mean)).sum() / float(n) / c0
return round(acf_lag, 3)
x = numpy.arange(n) # Avoiding lag 0 calculation
acf_coeffs = map(r, x)
return acf_coeffs
I am using this numpy array:
a=numpy.array([1, 2, 3,7,2,5,1,6,7,2,1,1,1,6,7,2])
And I am calling this code like this:
z2=acf(a)
print (z2)
Then the terminal returns:
<map object at 0x ....>
(not sure what the number is so better not write down here)
How can I call this function for autocorrelation lags 1,2,3,4 and such correctly?
Please help!