Probability distribution in Python

后端 未结 12 2068
误落风尘
误落风尘 2020-12-02 08:12

I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to

12条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 08:47

    I would use this recipe . You will need to add a weight to your objects, but that is just a simple ratio and put them in a list of tuples (object, conviction/(sum of convictions)). This should be easy to do using a list comprehension.

提交回复
热议问题