Message368307
I've seen multiple requests for this and it isn't obvious how to do it with the existing tooling.
The example currently given in the recipes section isn't scalable because it involves expanding the population into a big list with repeated elements:
sample(['x', 'x', 'x', 'x', 'y', 'y', 'z'], k=5)
Example task: Given an urn with 8 red balls, 2 white balls, and 3 green balls, choose ten without replacement:
>>> population = ['red', 'blue', 'green']
>>> weights = [ 8, 5, 3 ]
>>> sample(population, weights=weights, k=10)
['red', 'green', 'blue', 'red', 'green', 'blue', 'red', 'blue', 'red', 'blue']
I could also add *cum_weights* as an optional optimization but think it best to wait until someone asks for it ;-) |
|
Date |
User |
Action |
Args |
2020-05-06 22:35:20 | rhettinger | set | recipients:
+ rhettinger, tim.peters |
2020-05-06 22:35:20 | rhettinger | set | messageid: <1588804520.3.0.249071627671.issue40541@roundup.psfhosted.org> |
2020-05-06 22:35:20 | rhettinger | link | issue40541 messages |
2020-05-06 22:35:19 | rhettinger | create | |
|