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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -