I want to select a number from a list with a given probability.
I use numpy and I have defined a list to choose from. I also have a probability distribution matching the entries of my list.
from numpy import random
a = [0, 1] # select one entry from this list
p = [0.0, 1.0] # probability distribution
print(random.choice(a, 1, p))
With the distribution p I should only receive 1. However, when I run my code, I receive 0 too often. I think my distribution doesn't really affect the selection.
Aucun commentaire:
Enregistrer un commentaire