def factorial(n,exact=False):
if exact:<EOL><INDENT>if n < <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>val = <NUM_LIT:1><EOL>for k in xrange(<NUM_LIT:1>,n+<NUM_LIT:1>):<EOL><INDENT>val *= k<EOL><DEDENT>return val<EOL><DEDENT>else:<EOL><INDENT>n = asarray(n)<EOL>vals = gamma(n+<NUM_LIT:1>)<EOL>return where(n >= <NUM_LIT:0>,vals,<NUM_LIT:0>)<EOL><DEDENT>
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=False 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