Multi-precision floating-point `scipy.misc.comb`

157 Views Asked by At

I am using mpmath to write a binomial beta function fit to calculate extremely small probabilities.

Most of the functions I need are already included in mpmath or easy to rewrite. Sadly, however, scipy.misc.comb is not. I tried looking at the source code, but it seems to be based on some binom function imported from a file in which I cannot find its code.

How could I rewrite the scipy comb function (or write my own) without using for/while loops to calculate the factorials?

1

There are 1 best solutions below

0
On

Ok, so apparently mpmath does have a factorial function, with the deceptively intuitive name, mpmath.factorial -.-

So the solution to my query is simply:

def mp_comb(N,k):
    val= mpmath.factorial(N)/(mpmath.factorial(k)*mpmath.factorial(N-k))
    return val