scipy.stats seed?

后端 未结 4 961
滥情空心
滥情空心 2021-02-06 22:51

I am trying to generate scipy.stats.pareto.rvs(b, loc=0, scale=1, size=1) with different seed.

In numpy we can seed using numpy.random.seed(seed=233423).

Is ther

4条回答
  •  失恋的感觉
    2021-02-06 23:31

    For those who happen upon this post four years later, Scipy DOES provide a way to pass a np.random.RandomState object to its random variable classes, see rv_continuous and rv_discrete for more details. The scipy documentation says this:

    seed : None or int or numpy.random.RandomState instance, optional

    This parameter defines the RandomState object to use for drawing random variates. If None (or np.random), the global np.random state is used. If integer, it is used to seed the local RandomState instance. Default is None.

    Unfortunately, it appears this argument is not available after the continuous/discrete rvs subclass rv_continuous or rv_discrete. However, the random_state property does belong to the sublass, meaning we can set the seed using an instance of np.random.RandomState after instantiation like so:

    import numpy as np
    import scipy.stats as stats
    
    alpha_rv = stats.alpha(3.57)
    alpha_rv.random_state = np.random.RandomState(seed=342423)
    

提交回复
热议问题