Morlock - 1 year ago 110

Python Question

I need to compute combinatorials (nCr) in Python but cannot find the function to do that in

`math`

`numpy`

`stat`

`comb = calculate_combinations(n, r)`

I need the number of possible combinations, not the actual combinations, so

`itertools.combinations`

Finally, I want to avoid using factorials, as the numbers I'll be calculating the combinations for can get too big and the factorials are going to be monstrous.

This seems like a REALLY easy to answer question, however I am being drowned in questions about generating all the actual combinations, which is not what I want. :)

Many thanks

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

See scipy.misc.comb. When `exact`

is False, it uses the gammaln function to obtain good precision without taking much time. In the exact case it returns an arbitrary-precision integer, which might take a long time to compute.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**