Adding noise to numpy array Adding noise to numpy array numpy numpy

Adding noise to numpy array


Maybe I'm missing something, but have you tried adding numpy.random.normal(scale=20,size=100) to Y? You can even write

Y=numpy.random.normal(2*X+2,20)

and do it all at once (and without repeating the array size).


To simulate noise use a normally distributed random number generator like np.random.randn.

Is this what you are trying to do:

X = np.linspace(0, 1000, 100)Y = (2*X) + 2 + 20*np.random.randn(100)data = np.hstack((X.reshape(100,1),Y.reshape(100,1)))

enter image description here