scipy.special.binom#

scipy.special.binom(x, y, out=None) = <ufunc 'binom'>#

Binomial coefficient considered as a function of two real variables.

For real arguments, the binomial coefficient is defined as

\[\binom{x}{y} = \frac{\Gamma(x + 1)}{\Gamma(y + 1)\Gamma(x - y + 1)} = \frac{1}{(x + 1)\mathrm{B}(x - y + 1, y + 1)}\]

Where \(\Gamma\) is the Gamma function (gamma) and \(\mathrm{B}\) is the Beta function (beta) [1].

Parameters:
x, y: array_like

Real arguments to \(\binom{x}{y}\).

outndarray, optional

Optional output array for the function values

Returns:
scalar or ndarray

Value of binomial coefficient.

See also

comb

The number of combinations of N things taken k at a time.

Notes

The Gamma function has poles at non-positive integers and tends to either positive or negative infinity depending on the direction on the real line from which a pole is approached. When considered as a function of two real variables, \(\binom{x}{y}\) is thus undefined when x is a negative integer. binom returns nan when x is a negative integer. This is the case even when x is a negative integer and y an integer, contrary to the usual convention for defining \(\binom{n}{k}\) when it is considered as a function of two integer variables.

References

Examples

The following examples illustrate the ways in which binom differs from the function comb.

>>> from scipy.special import binom, comb

When exact=False and x and y are both positive, comb calls binom internally.

>>> x, y = 3, 2
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(3.0, 3.0, 3)

For larger values, comb with exact=True no longer agrees with binom.

>>> x, y = 43, 23
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(960566918219.9999, 960566918219.9999, 960566918220)

binom returns nan when x is a negative integer, but is otherwise defined for negative arguments. comb returns 0 whenever one of x or y is negative or x is less than y.

>>> x, y = -3, 2
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(nan, 0.0, 0)
>>> x, y = -3.1, 2.2
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(18.714147876804432, 0.0, 0)
>>> x, y = 2.2, 3.1
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(0.037399983365134115, 0.0, 0)