lundi 22 juin 2020

Creating a "mutation" using lambda but a different random number is used everytime using numpy arrays

Here is my code:

mut1 = np.zeros((100,52))
mutate = lambda mut1 : mut1 + (np.random.uniform(0,1) > 0.5) * np.random.uniform(-0.1,0.1)
mut1 = mutate(mut1)
print(mut1)

[[-0.02017634 -0.02017634 -0.02017634 ... -0.02017634 -0.02017634
  -0.02017634]
 [-0.02017634 -0.02017634 -0.02017634 ... -0.02017634 -0.02017634
  -0.02017634]
 [-0.02017634 -0.02017634 -0.02017634 ... -0.02017634 -0.02017634
  -0.02017634]
 ...
 [-0.02017634 -0.02017634 -0.02017634 ... -0.02017634 -0.02017634
  -0.02017634]
 [-0.02017634 -0.02017634 -0.02017634 ... -0.02017634 -0.02017634
  -0.02017634]
 [-0.02017634 -0.02017634 -0.02017634 ... -0.02017634 -0.02017634
  -0.02017634]]

THe problem is that each element in my mut1 array gets the same mutation.




Aucun commentaire:

Enregistrer un commentaire