bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / random / _generator / Generator / geometric
cython_function_or_method
numpy.random._generator:Generator.geometric
Signature
def geometric ( p , size = None ) Summary
Draw samples from the geometric distribution.
Extended Summary
Bernoulli trials are experiments with one of two outcomes: success or failure (an example of such an experiment is flipping a coin). The geometric distribution models the number of trials that must be run in order to achieve success. It is therefore supported on the positive integers, k = 1, 2, ....
The probability mass function of the geometric distribution is
where p is the probability of success of an individual trial.
Parameters
p: float or array_like of floatsThe probability of success of an individual trial.
size: int or tuple of ints, optionalOutput shape. If the given shape is, e.g.,
(m, n, k), thenm * n * ksamples are drawn. If size isNone(default), a single value is returned ifpis a scalar. Otherwise,np.array(p).sizesamples are drawn.
Returns
out: ndarray or scalarDrawn samples from the parameterized geometric distribution.
Examples
Draw 10,000 values from the geometric distribution, with the probability of an individual success equal to ``p = 0.35``:p, size = 0.35, 10000 rng = np.random.default_rng() sample = rng.geometric(p=p, size=size)✓
(sample == 1).sum()/size
✗import matplotlib.pyplot as plt count, bins, _ = plt.hist(sample, bins=30, density=True)✓
plt.plot(bins, (1-p)**(bins-1)*p) plt.xlim([0, 25])✗
plt.show()
✓
Aliases
-
numpy.random.Generator.geometric