combination function in python
Mark Dickinson
dickinsm at gmail.com
Sun Apr 15 16:58:38 EDT 2007
On Apr 15, 3:33 pm, bearophileH... at lycos.com wrote:
> With few tests, it seems this is faster than the version by Jussi only
> with quite big n,k.
>
True---and for large n and k it's difficult to imagine any real-world
applications that wouldn't be better served by using the lngamma
function instead. That is, the natural log of n choose k can be
computed much more quickly as
lngamma(n+1) - lngamma(k+1) - lngamma(n-k+1)
I assume that lngamma is implemented somewhere in either numpy or
scipy, but right now I can't find it...
Mark
More information about the Python-list
mailing list