bundles / scipy 1.18.0 / scipy / special / _basic / comb
function
scipy.special._basic:comb
source: /scipy/special/_basic.py:2602
Signature
def comb(N, k, *, exact = False, repetition = False)Summary
The number of combinations of N things taken k at a time.
Extended Summary
This is often expressed as "N choose k".
Parameters
N: int, ndarrayNumber of things.
k: int, ndarrayNumber of elements taken.
exact: bool, optionalFor integers, if
exactis False, then floating point precision is used, otherwise the result is computed exactly.repetition: bool, optionalIf
repetitionis True, then the number of combinations with repetition is computed.
Returns
val: int, float, ndarrayThe total number of combinations.
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
import numpy as np 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) comb(10, 3, exact=True, repetition=True)✓
220
See also
- binom
Binomial coefficient considered as a function of two real variables.
Aliases
scipy.special.comb