【发布时间】:2022-01-04 23:20:29
【问题描述】:
如果第二次执行,我对np.random.randn(n) 的印象会产生不同的样本。
如果第二次执行,np.random.RandomState(n_clusters).randn(n) 会产生相同的样本。它是否正确?另外,np.random.seed() 是做什么的?
我的代码:
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 ])
【问题讨论】:
标签: python arrays numpy random random-seed