scipy.special.comb#

scipy.special.comb(N, k, exact=False, repetition=False, legacy=True)[source]#

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

This is often expressed as “N choose k”.

Parameters
Nint, ndarray

Number of things.

kint, ndarray

Number of elements taken.

exactbool, optional

For integers, if exact is False, then floating point precision is used, otherwise the result is computed exactly. For non-integers, if exact is True, the inputs are currently cast to integers, though this behavior is deprecated (see below).

repetitionbool, optional

If repetition is True, then the number of combinations with repetition is computed.

legacybool, optional

If legacy is True and exact is True, then non-integral arguments are cast to ints; if legacy is False, the result for non-integral arguments is unaffected by the value of exact.

Deprecated since version 1.9.0: Non-integer arguments are currently being cast to integers when exact=True. This behaviour is deprecated and the default will change to avoid the cast in SciPy 1.11.0. To opt into the future behavior set legacy=False. If you want to keep the argument-casting but silence this warning, cast your inputs directly, e.g. comb(int(your_N), int(your_k), exact=True).

Returns
valint, float, ndarray

The total number of combinations.

See also

binom

Binomial coefficient considered as a function of two real variables.

Notes

  • Array arguments accepted only for exact=False case.

  • If N < 0, or k < 0, then 0 is returned.

  • If k > N and repetition=False, then 0 is returned.

Examples

>>> from scipy.special import comb
>>> k = np.array([3, 4])
>>> n = np.array([10, 10])
>>> comb(n, k, exact=False)
array([ 120.,  210.])
>>> comb(10, 3, exact=True)
120
>>> comb(10, 3, exact=True, repetition=True)
220