NumpyRNGContext#
- class astropy.utils.misc.NumpyRNGContext(seed)[源代码]#
基类:
object
上下文管理器(用于
with
语句)将把numpy随机数生成器(RNG)种子设定为特定值,然后将RNG状态恢复到以前的状态。这主要是为了用于天体试验服,但它可能有助于确保蒙特卡罗模拟在科学背景下的再现性。
- 参数:
- seed :
int
Python :整型 用于为numpy RNG设定种子的值
- seed :
实例
典型的用例可能是:
with NumpyRNGContext(<some seed value you pick>): from numpy import random randarr = random.randn(100) ... run your test using `randarr` ... #Any code using numpy.random at this indent level will act just as it #would have if it had been before the with statement - e.g. whatever #the default seed is.