mercredi 11 novembre 2020

Generating weighted intervals in Python

I know how to produce a weighted integer with random.choice.

Now I have 5000 integers from 0 to 1000. I want to have say 75% to land in the inerval 0-500, 20% 501-750 and 5% between 751-1000. What I tried and failed is

x = random.choice([np.arange(501), np.arange(501,751), np.arange(751, 1001)], size=5000, p=[0.75, 0.2, 0.05])

But then I only get random aranged intervals. Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire