132,696 views
0 votes
0 votes
Write Python code that produces an array called epsilon of length 10000 for which plt.acorr(epsilon), the plot of correlation between values, produces a plot with a correlation above 0.25 at lags 0,1 and 2, and has a correlation below 0.05 for lags strictly larger than 2. Hand in your code and your plot.

User Barry The Wizard
by
3.2k points

1 Answer

3 votes
3 votes

Answer:

Check the explanation

Step-by-step explanation:

acorr() is function in matplotlib module in python. acorr() in full meaning is Auto-Correlation function(). and it it generally used to find out Auto-Correlation of array of x element.

matplotlib.pyplot.acorr()

# Implementation acorr()

import matplotlib.pyplot as plt

import numpy as np

epsilon= np.random.randn(1000)

plt.title("Autocorrelation")

plt.acorr(epsilon, usevlines = True,

normed = True, maxlags =2,

lw = 3)

plt.grid(True)

plt.show()

also i have created the exmaple for both Auto as well as cross correlation as below

import matplotlib.pyplot as plt

import numpy as np

np.random.seed(10**3)

x, y = np.random.randn(2, 1000)

fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)

ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)

ax2.grid(True)

ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)

ax1.grid(True)

plt.show()

User Himani Sharma
by
3.1k points