get_state() after generating many numbers: will not retrieve s.get_state() after generating numbers: may or may not retrieve s, but it will not recreate the current state (at get_state()).get_state() immediately after setting: retrieves s that exactly recreates the state.Why the inconvenient discrepancy? No clue. Hence, numbers differ because when not setting a seed, pos = 623 - whereas if we use np.ed, pos = 624. However: np.t_state(state0)Īssert np.random.randint(0, 10, 1) = rand0Īnd likewise for state1 & rand1. We generated a number, yet get_state() remained identical. To illustrate: import numpy as npĪssert all(s0 = s1 for s0, s1 in zip(state0, state1)) The complete representation includes pos = get_state(). Refer to answer it may, however, mislead: the generated numbers differ not due to inability to map states, but that an incomplete encoding is used: get_state(). Original random seeds (set via np.ed) cannot be retrieved after generating numbers, but intermediates (current state) can. This answer complements important details others missed. It's therefore impossible to map every RNG state to a unique integer seed. See the difference? np.random.get_state() is identical for Output 1 and Output 2, but the rest of the output is not (most importantly the random numbers are not the same). The following snippet uses np.random.randint() to generate 5 random integers between -10 and 10, as well as storing some info about the process: Note that you'll most likely have to shut down and restart your kernel completely (or call np.ed(None)) in order to be able to see this. The next code section will also show that you can not take the first number of any random state using np.random.get_state() and expect to recreate that exact scenario. But then you'd already know what your random seed was before, so you wouldn't need to do it that way. It may not seem so at first though, because you could use np.ed(123), retrieve the same number with seed = np.random.get_state(), reset the seed with np.ed(444), and then (seemingly) set it back to the 123 scenario with np.ed(seed). Statement 2 - It will, however, be of little use to you: And using seed = np.random.get_state() will give you 123. You can easily see 123 as the first number in the array contained in the second element. I'm using a screenshot since using print(state) will flood your console because of the size of the array in the second element of the tuple. Below is a closer look at state (I'm using the Variable explorer in Spyder). If you set the random seed using np.ed(123), you can retrieve the random state as a tuple using state = np.random.get_state(). Statement 1 - you can find the random seed using np.random.get_state(). The output from the following code sections will show you why both statements are correct.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |