samedi 28 mars 2015

NumPy random seed produces different random numbers

I run the following code:



np.random.RandomState(3)
idx1 = np.random.choice(range(20),(5,))
idx2 = np.random.choice(range(20),(5,))
np.random.RandomState(3)
idx1S = np.random.choice(range(20),(5,))
idx2S = np.random.choice(range(20),(5,))


The output I get is the following:



idx1: array([ 2, 19, 19, 9, 4])
idx1S: array([ 2, 19, 19, 9, 4])

idx2: array([ 9, 2, 7, 10, 6])
idx2S: array([ 5, 16, 9, 11, 15])


idx1 and idx1S match, but idx2 and idx2S do not match. I expect that once I seed the random number generator and repeat the same sequence of commands - it should produce the same sequence of random numbers. Is this not true? Or is there something else that I am missing?





Aucun commentaire:

Enregistrer un commentaire