Say I want to draw from a list of bernoulli distributions at once, e.g. with probabilities [0.1, 0.2, 0.3]
. I could do this with a for loop but is there a better numpy way (use of scipy is also fine)?
ps = [0.1, 0.2, 0.3]
[np.random.choice(2, p=[1 - p, p]) for p in ps]
Aucun commentaire:
Enregistrer un commentaire