Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé
Module « scipy.special »

Fonction factorial - module scipy.special

Signature de la fonction factorial

def factorial(n, exact=False, extend='zero') 

Description

help(scipy.special.factorial)

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

Parameters
----------
n : int or float or complex (or array_like thereof)
    Input values for ``n!``. Complex values require ``extend='complex'``.
    By default, the return value for ``n < 0`` is 0.
exact : bool, optional
    If ``exact`` is set to True, calculate the answer exactly using
    integer arithmetic, otherwise approximate using the gamma function
    (faster, but yields floats instead of integers).
    Default is False.
extend : string, optional
    One of ``'zero'`` or ``'complex'``; this determines how values ``n<0``
    are handled - by default they are 0, but it is possible to opt into the
    complex extension of the factorial (see below).

Returns
-------
nf : int or float or complex or ndarray
    Factorial of ``n``, as integer, float or complex (depending on ``exact``
    and ``extend``). Array inputs are returned as arrays.

Notes
-----
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 (which is also the definition of the complex extension):

.. math:: n! = \Gamma(n+1)

Examples
--------
>>> import numpy as np
>>> 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)
120



Vous êtes un professionnel et vous avez besoin d'une formation ? Calcul scientifique
avec Python
Voir le programme détaillé