mardi 13 septembre 2022

Adding random values to python list elements

I have a list :

a = [1,2,3,4,5,6,7,8,9,10]

I want to add a different random number to each element in the list using np.random.randn() I start by creating another list containing the rando values by using:

noise = []
for i in range(len(a)):
    b = (random_noise * np.random.randn())
    noise.append(b)

And the add the two lists

a + b 

My question is, is there a simplified method in which i can add the noise directly to a elements without the need to creating the loop, in seek of saving time in the large problems.




Aucun commentaire:

Enregistrer un commentaire