vendredi 27 décembre 2019

Python: Long list with weighted probabilities, choose one element [duplicate]

This question already has an answer here:

I have two lists, each of length 100. The first list contains indices (call this list i) and the second contains the probability that each of those indices will be selected (call this list P). I would like to choose one index using the given probabilities.

I have tried to use the following code:

index = random.choice(i, P)

to select one index from the list. However, I get the error:

ValueError: sequence too large; cannot be greater than 32

Is there a way to get around this error and select an element from a larger (100 element) list with weighted probabilities? Perhaps there is another function besides numpy.random() that I can use? Or maybe a way to look at only 32 elements of the list at one time (although I'm concerned about altering the given probability distribution)? Thank you in advance for your help!




Aucun commentaire:

Enregistrer un commentaire