[SciPy-user] calculating factorial

Robert Kern robert.kern at gmail.com
Sat Nov 19 08:45:01 CST 2005

Stefan van der Walt wrote:
> I couldn't find "factorial", "combination", "permutation" etc. in
> SciPy.  Luckily, they're simple -- only problem is that my
> implementation doesn't work :)
> See the code listing below.  I thought that the two methods for
> calculating factorials should work equally well.  I get an integer
> overflow, no matter what typecode I use.

100! simply isn't representable by any of the numerical datatypes in
Numeric or scipy_core. It's too large. However, you can use arrays of
Python objects to utilize Python's long integers.

In scipy_core:

In [11]: a  = array(range(2,101), dtype=object)

In [12]: multiply.reduce(a)

Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the SciPy-user mailing list