Message277486
Equidistributed examples:
choices(c.execute('SELECT name FROM Employees').fetchall(), k=20)
choices(['hearts', 'diamonds', 'spades', 'clubs'], k=5)
choices(list(product(card_facevalues, suits)), k=5)
Weighted selection examples:
Counter(choices(['red', 'black', 'green'], [18, 18, 2], k=3800)) # american roulette
Counter(choices(['hit', 'miss'], [5, 1], k=600)) # russian roulette
choices(fetch('employees'), fetch('years_of_service'), k=100) # tenure weighted
choices(cohort, map(cancer_risk, map(risk_factors, cohort)), k=50) # risk weighted
Star unpacking example:
transpose = lambda s: zip(*s)
craps = [(2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6), (8, 5), (9, 4), (10, 3), (11, 2), (12, 1)]
print(choices(*transpose(craps), k=10))
Comparative APIs from other languages:
http://www.mathworks.com/help/stats/randsample.html
http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.choice.html
https://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html
https://reference.wolfram.com/language/ref/RandomChoice.html |
|
Date |
User |
Action |
Args |
2016-09-27 04:56:07 | rhettinger | set | recipients:
+ rhettinger, tim.peters, mark.dickinson, pitrou, aisaac, westley.martinez, python-dev, serhiy.storchaka, NeilGirdhar, madison.may, dkorchem, Christian.Kleineidam, davin, xksteven |
2016-09-27 04:56:07 | rhettinger | set | messageid: <1474952167.72.0.771872806262.issue18844@psf.upfronthosting.co.za> |
2016-09-27 04:56:07 | rhettinger | link | issue18844 messages |
2016-09-27 04:56:06 | rhettinger | create | |
|