cpython (3.6): Add cum_weights example (simulation of a cumulative binomial distribution).
https://hg.python.org/cpython/rev/fc6f90d8022b changeset: 104864:fc6f90d8022b branch: 3.6 parent: 104862:d3a42b934a0d user: Raymond Hettinger <python@rcn.com> date: Mon Oct 31 22:53:52 2016 -0700 summary: Add cum_weights example (simulation of a cumulative binomial distribution). files: Doc/library/random.rst | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -351,6 +351,13 @@ >>> 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 -- Repository URL: https://hg.python.org/cpython
participants (1)
-
raymond.hettinger