vendredi 26 novembre 2021

Difference between Numpy Randn and RandomState

My impression about the np.random.randn(n) produces different samples if executed second time. np.random.RandomState(n_clusters).randn(n) produces same samples if executed second time. Is this correct? Also, what does np.random.seed() does?

My code:

np.random.RandomState(2).randn(2)
Out[6]: array([-0.41675785, -0.05626683])

np.random.RandomState(4).randn(2)
Out[7]: array([0.05056171, 0.49995133])

np.random.RandomState(42).randn(2)
Out[8]: array([ 0.49671415, -0.1382643 ])

np.random.RandomState(42).randn(2)
Out[9]: array([ 0.49671415, -0.1382643 ])

np.random.RandomState(4).randn(2)
Out[10]: array([0.05056171, 0.49995133])

np.random.RandomState(2).randn(2)
Out[11]: array([-0.41675785, -0.05626683])

np.random.randn(2)
Out[12]: array([ 0.47143516, -1.19097569])

np.random.randn(2)
Out[13]: array([ 1.43270697, -0.3126519 ])



Aucun commentaire:

Enregistrer un commentaire