相关疑难解决方法(0)

加权选择简短

如果我在列表中有一组项目.我想根据另一个权重列表从该列表中进行选择.

例如我的收藏是['one', 'two', 'three']和权重[0.2, 0.3, 0.5],我希望这个方法在所有抽奖的大约一半中给我'三'.

最简单的方法是什么?

python numpy

46
推荐指数
4
解决办法
4万
查看次数

从python中的权重数组中获取随机索引的快速方法

I regularly find myself in the position of needing a random index to an array or a list, where the probabilities of indices are not uniformly distributed, but according to certain positive weights. What's a fast way to obtain them? I know I can pass weights to numpy.random.choice as optional argument p, but the function seems quite slow, and building an arange to pass it is not ideal either. The sum of weights can be an arbitrary positive number …

python random algorithm

3
推荐指数
1
解决办法
1134
查看次数

标签 统计

python ×2

algorithm ×1

numpy ×1

random ×1