小编joh*_*ack的帖子

numpy.random 的 Generator 类和 np.random 方法有什么区别?

我已经使用 numpy 的随机功能一段时间了,通过调用诸如np.random.choice()或np.random.randint()等方法。我现在发现了创建一个default_rng对象或其他Generator对象的能力:

from numpy.random import default_rng
gen = default_rng()
random_number = gen.integers(10)
Run Code Online (Sandbox Code Playgroud)

到目前为止我一直会使用

np.random.randint(10)
Run Code Online (Sandbox Code Playgroud)

相反,我想知道这两种方式有什么区别。

我能想到的唯一好处是跟踪多个种子,或者想要使用特定的 PRNG,但对于更通用的用例来说,也许也存在差异?

python random numpy numpy-random

8
推荐指数
1
解决办法
2316
查看次数

标签 统计

numpy ×1

numpy-random ×1

python ×1

random ×1