How do I sample randomly based on some probability(wightage)?
Peter Otten
__peter__ at web.de
Sun May 31 18:11:06 CEST 2009
Scott David Daniels wrote:
> raise ValueError('Samplng more than %d without replacement?' % (
> sum(1 for w in weights)))
That would be len(weights)
> There were two mistakes, both related to the definition of combined:
> (1) Combined only holds positive values, so testing in sum is silly.
but I think your first version was correct; I don't see were you remove the
0-items from weights.
Peter
More information about the Python-list
mailing list