samedi 20 mars 2021

How to randomly choose a tuple from a list of tuples

I need to randomly choose a tuple from a list of tuples given probabilities to be chosen for each tuple.

I'm trying the following code:

from numpy.random import choice
v = [(0, 0), (0, 1), (1, 0), (1, 1)]
pr = [0.3, 0.2, 0.1, 0.4]
print(choice(v, p=pr))

However, I get this message: ValueError: a must be 1-dimensional

How can fix that issue?




Aucun commentaire:

Enregistrer un commentaire