SciPy

scipy.special.comb

scipy.special.comb(N, k, exact=False, repetition=False)[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

If exact is False, then floating point precision is used, otherwise exact long integer is computed.

repetitionbool, optional

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

Returns
valint, float, ndarray

The total number of combinations.

See also

binom

Binomial coefficient ufunc

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)
120L
>>> comb(10, 3, exact=True, repetition=True)
220L

Previous topic

scipy.special.keip_zeros

Next topic

scipy.special.perm