@@ -3423,19 +3423,34 @@ cdef class Generator:
3423
3423
out : ndarray or scalar
3424
3424
Drawn samples from the parameterized geometric distribution.
3425
3425
3426
+ References
3427
+ ----------
3428
+
3429
+ .. [1] Wikipedia, "Geometric distribution",
3430
+ https://en.wikipedia.org/wiki/Geometric_distribution
3431
+
3426
3432
Examples
3427
3433
--------
3428
- Draw ten thousand values from the geometric distribution,
3429
- with the probability of an individual success equal to 0.35:
3434
+ Draw 10.000 values from the geometric distribution, with the
3435
+ probability of an individual success equal to ``p = 0.35`` :
3430
3436
3437
+ >>> p, size = 0.35, 10000
3431
3438
>>> rng = np.random.default_rng()
3432
- >>> z = rng.geometric(p=0.35 , size=10000 )
3439
+ >>> sample = rng.geometric(p=p , size=size )
3433
3440
3434
- How many trials succeeded after a single run?
3441
+ What proportion of trials succeeded after a single run?
3435
3442
3436
- >>> (z == 1).sum() / 10000.
3437
- 0.34889999999999999 # random
3443
+ >>> (sample == 1).sum()/size
3444
+ 0.34889999999999999 # may vary
3438
3445
3446
+ The geometric distribution with ``p=0.35`` looks as follows:
3447
+
3448
+ >>> import matplotlib.pyplot as plt
3449
+ >>> count, bins, _ = plt.hist(sample, bins=30, density=True)
3450
+ >>> plt.plot(bins, (1-p)**(bins-1)*p)
3451
+ >>> plt.xlim([0, 25])
3452
+ >>> plt.show()
3453
+
3439
3454
"""
3440
3455
return disc (& random_geometric , & self ._bitgen , size , self .lock , 1 , 0 ,
3441
3456
p , 'p' , CONS_BOUNDED_GT_0_1 ,
0 commit comments