gpt4 book ai didi

python - 为什么我可以调用 Numpy RandomState 方法?

转载 作者:太空宇宙 更新时间:2023-11-03 12:01:17 24 4
gpt4 key购买 nike

我正在学习 Python,我发现了以下代码:

rgen = np.random.RandomState(self.random_state)

在这段代码中,self.random_state 是一个int。我看着 documentation并发现 RandomState(int) 不作为方法存在,而只是一个“方法容器”。

那么,如何调用 RandomState(self.random_state) 呢?

最佳答案

RandomState 是一个类,RandomState(whatever_arguments) 只是创建类 RandomState 的一个新实例。

实例创建通常通过 __init__(和/或 __new__),这是一种特殊方法,并不总是单独记录。通常,在这种情况下,它记录在类的文档字符串中,您已经链接到相关的 documentation page其中列出了实例创建的参数:

class numpy.random.RandomState

Container for the Mersenne Twister pseudo-random number generator.

RandomState exposes a number of methods for generating random numbers drawn from a variety of probability distributions. In addition to the distribution-specific arguments, each method takes a keyword argument size that defaults to None. If size is None, then a single value is generated and returned. If size is an integer, then a 1-D array filled with generated values is returned. If size is a tuple, then an array with that shape is filled and returned.

Compatibility Guarantee A fixed seed and a fixed series of calls to ‘RandomState’ methods using the same parameters will always produce the same results up to roundoff error except when the values were incorrect. Incorrect values will be fixed and the NumPy version in which the fix was made will be noted in the relevant docstring. Extension of existing parameter ranges and the addition of new parameters is allowed as long the previous behavior remains unchanged.

Parameters:

seed : {None, int, array_like}, optional

Random seed used to initialize the pseudo-random number generator. Can be any integer between 0 and 2**32 - 1 inclusive, an array (or other sequence) of such integers, or None (the default). If seed is None, then RandomState will try to read data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise.

关于python - 为什么我可以调用 Numpy RandomState 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47952914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com