np_random_state#
- np_random_state(random_state_argument)[source]#
Decorator to generate a numpy RandomState or Generator instance.
The decorator processes the argument indicated by
random_state_argument
usingnx.utils.create_random_state()
. The argument value can be a seed (integer), or anumpy.random.RandomState
ornumpy.random.RandomState
instance or (None
ornumpy.random
). The latter two options use the global random number generator fornumpy.random
.The returned instance is a
numpy.random.RandomState
ornumpy.random.Generator
.- Parameters:
- random_state_argumentstring or int
The name or index of the argument to be converted to a
numpy.random.RandomState
instance.
- Returns:
- _random_statefunction
Function whose random_state keyword argument is a RandomState instance.
See also
Examples
Decorate functions like this:
@np_random_state("seed") def random_float(seed=None): return seed.rand() @np_random_state(0) def random_float(rng=None): return rng.rand() @np_random_state(1) def random_array(dims, random_state=1): return random_state.rand(*dims)