python - 从python中的几何分布生成随机样本

标签 python numpy statistics distribution

我想使用 python 从几何分布生成随机样本。

我使用的是 numpy.random.geometric(p=0.3, size=100) 函数。但后来我意识到这个函数是用pmf从几何分布生成样本的:p*q^(x-1), x=1,2,3....

但我想要来自具有 pmf 的几何分布的随机样本:p*q^(x), x=0,1,2,...

请帮忙。

最佳答案

But I want random samples from geometric distribution with pmf: p*q^(x), x=0,1,2,...

您可以使用 NumPy 的 geometric 实现,然后从样本中减去一个:

In [37]: rng = np.random.default_rng()

In [38]: nsamples = 1000

In [39]: r = rng.geometric(0.3, size=nsamples) - 1

r 是您想要的分布中的样本。

关于python - 从python中的几何分布生成随机样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72593881/

相关文章:

python - 更新特定的 numpy 矩阵列

python - 连接两个Numpy图像数组时出现问题。引发错误 “only integer scalar arrays can be converted to a scalar index”

python - numpy search在切片上按字典顺序排序

sql-server-2005 - 查明索引和表统计信息是否过时

r - 在 R 中使用多核来分析 GWAS 数据

php - 是否有 PHP 的统计库?

python - pylint 如何记住之前运行的分数?

python - 将 Gtk.DrawingArea 或 Cairo 图案的内容保存到磁盘上的图像

python - 如何根据 python pandas 中的 1 个以上的独特类别过滤数据

python - 通过对数据进行分组来汇总 pandas 中的数据