Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting a seed for numpy uniform doesn't result in the same probabilities

Why doesn’t the below shown code result in 3 arrays with the same probabilities? How can I generate reproducible probabilities?

import numpy as np
np.random.seed(42)
for i in range(3):
    print(np.random.uniform(size = 10))

[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
 0.05808361 0.86617615 0.60111501 0.70807258]

[0.02058449 0.96990985 0.83244264 0.21233911 0.18182497 0.18340451
     0.30424224 0.52475643 0.43194502 0.29122914]

[0.61185289 0.13949386 0.29214465 0.36636184 0.45606998 0.78517596
     0.19967378 0.51423444 0.59241457 0.04645041]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You should reset the seed at the beginning of every loop.

import numpy as np
for i in range(3):
    np.random.seed(42)
    print(np.random.uniform(size = 10))
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
 0.05808361 0.86617615 0.60111501 0.70807258]
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
 0.05808361 0.86617615 0.60111501 0.70807258]
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
 0.05808361 0.86617615 0.60111501 0.70807258]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading