【问题标题】:How do you draw random numbers from a given scipy random distribution?你如何从给定的 scipy 随机分布中提取随机数?
【发布时间】:2021-04-16 08:48:20
【问题描述】:

我正在尝试从给定的 scipy stats 随机分布生成随机数,在我的例子中是负二项分布。

文档对我来说并不完全清楚。 不幸的是,文档有点稀疏:https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.nbinom.html

这应该很简单。

【问题讨论】:

    标签: python random scipy scipy.stats


    【解决方案1】:

    相关方法是rvs,代表随机变量。

    您可以从负二项分布中生成一个随机数,如下所示:

    import scipy.stats
    scipy.stats.nbinom.rvs(1,0.5) # returns 2 (or other random integer between 0 and +inf)
    

    【讨论】:

    • 这应该包含在帖子中,而不是作为答案。
    • @Pygirl 为什么?它的答案。或者你的意思是docu的链接?当然,这可以是任何一种方式。
    • documentation isn't entirely clear to me 在您的帖子中。 Unfortunately, the documentation is a bit sparse 在您的回答中。所以我以为你还没有找到答案。
    • 明白了,重新排列了一下。感谢您的评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 2012-03-10
    相关资源
    最近更新 更多