【发布时间】:2014-05-20 17:10:17
【问题描述】:
我需要根据二项分布随机生成一系列数字。 Numpy 的随机套件提供了一种方法来执行此操作,但不幸的是,它似乎仅限于处理 n 值的 32 位数字,我想使用该范围之外的值。 64 位就足够了,尽管任意更高的精度也可以。
示例输出:
>>> np.random.binomial(1<<40, 0.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mtrand.pyx", line 3506, in mtrand.RandomState.binomial (numpy\random\mtrand\mtrand.c:16555)
OverflowError: Python int too large to convert to C long
我可以使用其他替代方法吗?或者让 numpy 在这个随机生成器内部使用 64 位数字的方法?
或者我需要自己骑上马鞍并滚动吗?
(正如 Robert Klein 所指出的,numpy 确实在除 Windows 之外的 64 位平台上运行 64 位;不幸的是,我使用的是 Windows)。
【问题讨论】:
-
你能再解释一下吗?
np.random.binomial( np.iinfo(np.int64).max , 0.5)在我的笔记本电脑上运行良好。
标签: python python-3.x numpy random