This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / stats / _discrete_distns / hypergeom_gen

class

scipy.stats._discrete_distns:hypergeom_gen

source: build-install/usr/lib/python3.14/site-packages/scipy/stats/_discrete_distns.py:580

Signature

class hypergeom_gen(a = 0, b = inf, name = None, badvalue = None, moment_tol = 1e-08, values = None, inc = 1, longname = None, shapes = None, seed = None)

Members

Summary

A hypergeometric discrete random variable.

Extended Summary

The hypergeometric distribution models drawing objects from a bin. M is the total number of objects, n is total number of Type I objects. The random variate represents the number of Type I objects in N drawn without replacement from the total population.

%(before_notes)s

Notes

The symbols used to denote the shape parameters (M, n, and N) are not universally accepted. See the Examples for a clarification of the definitions used here.

The probability mass function is defined as,

for , where the binomial coefficients are defined as,

This distribution uses routines from the Boost Math C++ library for the computation of the pmf, cdf, sf and stats methods. [1]

%(after_notes)s

Examples

import numpy as np
from scipy.stats import hypergeom
import matplotlib.pyplot as plt
✓
Suppose we have a collection of 20 animals, of which 7 are dogs. Then if we want to know the probability of finding a given number of dogs if we choose at random 12 of the 20 animals, we can initialize a frozen distribution and plot the probability mass function:
[M, n, N] = [20, 7, 12]
rv = hypergeom(M, n, N)
x = np.arange(0, n+1)
pmf_dogs = rv.pmf(x)
✓
fig = plt.figure()
ax = fig.add_subplot(111)
✓
ax.plot(x, pmf_dogs, 'bo')
ax.vlines(x, 0, pmf_dogs, lw=2)
ax.set_xlabel('# of dogs in our group of chosen animals')
ax.set_ylabel('hypergeom PMF')
✗
Text(0, 0.5, 'hypergeom PMF')
plt.show()
✓
fig-2f29bf845adcfa8c.png
Instead of using a frozen distribution we can also use `hypergeom` methods directly. To for example obtain the cumulative distribution function, use:
prb = hypergeom.cdf(x, M, n, N)
✓
And to generate random numbers:
R = hypergeom.rvs(M, n, N, size=10)
✓

See also

binom
nbinom
nhypergeom

Aliases

  • scipy.stats._discrete_distns.hypergeom_gen