diff options
author | lzha97 <lz2527@columbia.edu> | 2022-12-10 17:04:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-10 19:04:13 -0300 |
commit | 825e3942dd380bd5303af61cc8a0a63fc703b0ee (patch) | |
tree | 6346a129ade575bad64d993558f0c78da758b620 /numpy | |
parent | 4ca8204c5c13b3a5c9482772813e67184f3f47c8 (diff) | |
download | numpy-825e3942dd380bd5303af61cc8a0a63fc703b0ee.tar.gz |
DOC: Add random generator exponential example (#22284)
* DOC: add examples for random generator exponential function (Issue #22270)
* DOC: fix doc test for random exponential generator example (Issue #22270)
* DOC: fix formatting on np.random.exponential example (Issue: #22270)
* DOC: fix test and problem context on np.random.exponential example (Issue: #22270)
* DOC: use may vary instead of will vary for exponential example (Issue: #22270)
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/random/_generator.pyx | 16 | ||||
-rw-r--r-- | numpy/random/mtrand.pyx | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx index da66c1cac..a5ca1b9f1 100644 --- a/numpy/random/_generator.pyx +++ b/numpy/random/_generator.pyx @@ -380,6 +380,22 @@ cdef class Generator: out : ndarray or scalar Drawn samples from the parameterized exponential distribution. + Examples + -------- + A real world example: Assume a company has 10000 customer support + agents and the average time between customer calls is 4 minutes. + + >>> n = 10000 + >>> time_between_calls = np.random.default_rng().exponential(scale=4, size=n) + + What is the probability that a customer will call in the next + 4 to 5 minutes? + + >>> x = ((time_between_calls < 5).sum())/n + >>> y = ((time_between_calls < 4).sum())/n + >>> x-y + 0.08 # may vary + References ---------- .. [1] Peyton Z. Peebles Jr., "Probability, Random Variables and diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index edf812a4d..ca6ba9de8 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -537,6 +537,22 @@ cdef class RandomState: out : ndarray or scalar Drawn samples from the parameterized exponential distribution. + Examples + -------- + A real world example: Assume a company has 10000 customer support + agents and the average time between customer calls is 4 minutes. + + >>> n = 10000 + >>> time_between_calls = np.random.default_rng().exponential(scale=4, size=n) + + What is the probability that a customer will call in the next + 4 to 5 minutes? + + >>> x = ((time_between_calls < 5).sum())/n + >>> y = ((time_between_calls < 4).sum())/n + >>> x-y + 0.08 # may vary + See Also -------- random.Generator.exponential: which should be used for new code. |