1
$\begingroup$

I'm trying to set the seed for a few lines of code in a jupyter notebook.

However, when I tried running numpy.random.seed(0) in the initial cell, in the later cells the random generator was not 'seeded'. I had to write a set seed in all the cells where I was running the random draws... Why is that? Is there a way to avoid having to write the same thing in every cell where I have a random draw?

Also, I checked the numpy documentation and it seems that numpy.random.seed() is not the best practice. I don't understand the example given there... How would I go about, according to the best practices shown in the example, in order to do something similar to numpy.random.seed(constant)?

$\endgroup$
6
  • 1
    $\begingroup$ This seems like an artifact of running in Jupyter. If you put all of that in a .py file that you run from the command line, the seeding will remain throughout the entirety of the script. $\endgroup$ – Dave Nov 18 '20 at 11:15
  • 1
    $\begingroup$ I think asking this in the main site of stack overflow will give you an answer much faster $\endgroup$ – Gulzar Nov 18 '20 at 18:19
  • 1
    $\begingroup$ Is this the same issue: stackoverflow.com/questions/51424857/…? $\endgroup$ – Burger Nov 18 '20 at 19:56
  • $\begingroup$ @Burger, yes, it is. Thanks ;) $\endgroup$ – An old man in the sea. Nov 22 '20 at 9:05
  • $\begingroup$ @Gulzar thanks ;) $\endgroup$ – An old man in the sea. Nov 22 '20 at 9:06

Browse other questions tagged or ask your own question.