I would like to be able to fix the sequence of (pseudo) random numbers being generated by numpy
for reproducability of my research. We can usually achieve this result by fixing the random seed and I followed the same in Python by using np.random.seed
to fix the value. However, between two Python sessions I am seeing different results for the same random seed. Please find below the output from two sessions.
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.random.seed = 198908
>>> np.random.uniform(low=0.0, high=1.0, size=10)
array([ 0.43203804, 0.89881118, 0.02976592, 0.93286634, 0.21568609,
0.44705267, 0.27159611, 0.4000281 , 0.33873711, 0.54835523])
>>> exit()
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.random.seed = 198908
>>> np.random.uniform(low=0.0, high=1.0, size=10)
array([ 0.20178185, 0.22492203, 0.51029445, 0.4776532 , 0.49109006,
0.22807983, 0.86419725, 0.53422946, 0.08904607, 0.83125896])
>>> exit()
Am I missing something here? Also, can anyone suggest an approach that will generate consistent random draws across different machines (assuming same software version is installed)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…