Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # src is a dictionary, each key's value is its relative probability as an arbitrary numeric value
- items = []
- weights = []
- s = 0.0
- for k, v in src.items():
- items.append(k)
- weights.append(v)
- s += v
- weights = map(lambda x: x/s, weights)
- numpy.random.choice(items, p=weights)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement