scipy.misc.factorial¶
- scipy.misc.factorial(n, exact=0)[source]¶
The factorial function, n! = special.gamma(n+1).
If exact is 0, then floating point precision is used, otherwise exact long integer is computed.
- Array argument accepted only for exact=0 case.
- If n<0, the return value is 0.
Parameters : n : int or array_like of ints
Calculate n!. Arrays are only supported with exact set to False. If n < 0, the return value is 0.
exact : bool, optional
The result can be approximated rapidly using the gamma-formula above. If exact is set to True, calculate the answer exactly using integer arithmetic. Default is False.
Returns : nf : float or int
Factorial of n, as an integer or a float depending on exact.
Examples
>>> arr = np.array([3,4,5]) >>> sc.factorial(arr, exact=False) array([ 6., 24., 120.]) >>> sc.factorial(5, exact=True) 120L