Difference between np.random.seed() and np.random.RandomState()

前端 未结 4 1512
野的像风
野的像风 2020-11-30 17:58

I know that to seed the randomness of numpy.random, and be able to reproduce it, I should us:

import numpy as np
np.random.seed(1234)

but w

4条回答
  •  借酒劲吻你
    2020-11-30 18:57

    np.random.RandomState() constructs a random number generator. It does not have any effect on the freestanding functions in np.random, but must be used explicitly:

    >>> rng = np.random.RandomState(42)
    >>> rng.randn(4)
    array([ 0.49671415, -0.1382643 ,  0.64768854,  1.52302986])
    >>> rng2 = np.random.RandomState(42)
    >>> rng2.randn(4)
    array([ 0.49671415, -0.1382643 ,  0.64768854,  1.52302986])
    

提交回复
热议问题