scipy.misc.factorial(*args, **kwds)[source]

factorial is deprecated! Importing factorial from scipy.misc is deprecated in scipy 1.0.0. Use scipy.special.factorial instead.

The factorial of a number or array of numbers.

The factorial of non-negative integer n is the product of all positive integers less than or equal to n:

n! = n * (n - 1) * (n - 2) * ... * 1

n : int or array_like of ints

Input values. If n < 0, the return value is 0.

exact : bool, optional

If True, calculate the answer exactly using long integer arithmetic. If False, result is approximated in floating point rapidly using the gamma function. Default is False.


nf : float or int or ndarray

Factorial of n, as integer or float depending on exact.


For arrays with exact=True, the factorial is computed only once, for the largest input, with each other result computed in the process. The output dtype is increased to int64 or object if necessary.

With exact=False the factorial is approximated using the gamma function:

\[n! = \Gamma(n+1)\]


>>> from scipy.special import factorial
>>> arr = np.array([3, 4, 5])
>>> factorial(arr, exact=False)
array([   6.,   24.,  120.])
>>> factorial(arr, exact=True)
array([  6,  24, 120])
>>> factorial(5, exact=True)

Previous topic


Next topic