简体   繁体   中英

How to add gaussian noise (10%) to a set of datapoints

i have a set of 100 point (2-dimensional, xy). I have to add to each x-coordinate a 10% gaussian noise. The 10% is referred to each x-value. I've found around this line of code:

noisy_data = exact_data
relativeError = 0.1
noisy_data[:,0] = [ np.random.normal(loc=value, scale=abs(relativeError*value)) for value in noisy_data[:,1]] 

I'm not sure this is the right way to do that. Do you know if it is correct? If not, is there a function that can do it properly?

It sounds to me like the y values don't matter. Also, there's no need to iterate over each element.

noisy_data = exact_data.copy()
noisy_data[:, 0] += np.random.normal(loc=0, scale=abs(relativeError*noisy_data[:, 0]))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM