probability - Is there a built-in function to get a number when i have numbers and their probabilities? (Python) -
i have dictionary keys numbers , values probabilities. there (built-in) way return number? basically, want analog of randrange() custom probabilities. use of dictionary not necessary.
import numpy np d = {10:0.5, 9: 0.4, 8:0.1} x,p = zip(*d.items()) np.random.choice(x, p=p)
Comments
Post a Comment