diff options
author | Raymond Hettinger <python@rcn.com> | 2016-11-01 05:53:52 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-11-01 05:53:52 (GMT) |
commit | 16ef5d4ae120eb412562fd1826bc56863dc416e7 (patch) | |
tree | 6ecc8338f18f8b84d811957336673724454997c4 /Doc/library | |
parent | a9e99b1a543364c86d5d2cbc42007b192433702e (diff) | |
download | cpython-16ef5d4ae120eb412562fd1826bc56863dc416e7.zip cpython-16ef5d4ae120eb412562fd1826bc56863dc416e7.tar.gz cpython-16ef5d4ae120eb412562fd1826bc56863dc416e7.tar.bz2 |
Add cum_weights example (simulation of a cumulative binomial distribution).
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/random.rst | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst index a47ed9c..edf76d7 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -351,6 +351,13 @@ Basic usage:: >>> choices(['red', 'black', 'green'], [18, 18, 2], k=6) ['red', 'green', 'black', 'black', 'red', 'black'] + # Probability of getting 5 or more heads from 7 spins of a biased coin + # that settles on heads 60% of the time. + >>> n = 10000 + >>> cw = [0.60, 1.00] + >>> sum(choices('HT', cum_weights=cw, k=7).count('H') >= 5 for i in range(n)) / n + 0.4169 + Example of `statistical bootstrapping <https://en.wikipedia.org/wiki/Bootstrapping_(statistics)>`_ using resampling with replacement to estimate a confidence interval for the mean of a small |