def sample_signal(n_samples, corr, mu=0, sigma=1):
    assert 0 < corr < 1, 'Auto-correlation must be between 0 and 1'
c = mu * (1 - corr)
sigma_e = np.sqrt(sigma ** 2 * (1 - corr ** 2))
signal = [c + np.random.normal(0, sigma_e)]
for _ in range(1, n_samples):
    signal.append(c + corr * signal[-1] + np.random.normal(0, sigma_e))
return np.array(signal)

def compute_corr_lag_1(signal):
    return np.corrcoef(signal[:-1], signal[1:])[0][1]
print(compute_corr_lag_1(sample_signal(5000, 0.5)))
print(np.mean(sample_signal(5000, 0.5, mu=2)))
print(np.std(sample_signal(5000, 0.5, sigma=3)))
Python - generate array of specific autocorrelation