Numpy random seed valid for entire jupyter notebook

后端 未结 2 1626
[愿得一人]
[愿得一人] 2021-01-11 13:04

I\'m using functions from numpy.random on a Jupyter Lab notebook and I\'m trying to set the seed using numpy.random.seed(333). This works as expect

2条回答
  •  春和景丽
    2021-01-11 13:44

    Because you run np.random.choice() in the cells different from np.random.seed(). Try to run np.random.seed() and np.random.choice() in the same cell, you'll get same number.

    # in [11]
    import numpy as np
    # even if I set the seed here the other cells don't see it
    np.random.seed(333)
    np.random.choice([1,23,44,3,2])
    2
    # gets the same numbers
    
    # in [12]
    import numpy as np
    # even if I set the seed here the other cells don't see it
    np.random.seed(333)
    np.random.choice([1,23,44,3,2])
    2
    # gets the same numbers
    

提交回复
热议问题