{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For arrays with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "exact=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the factorial is computed only once, for the largest input, with each other result computed in the process. The output dtype is increased to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "int64"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "object"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " if necessary."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "With "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "exact=False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " the factorial is approximated using the gamma function (which is also the definition of the complex extension):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "n! = \\Gamma(n+1)"
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "nf",
              "annotation": "int or float or complex or ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Factorial of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", as integer, float or complex (depending on "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "exact"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "extend"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "). Array inputs are returned as arrays."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The factorial of a number or array of numbers."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n",
              "annotation": "int or float or complex (or array_like thereof)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Input values for "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n!"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Complex values require "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "extend='complex'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". By default, the return value for "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n < 0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is 0."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "exact",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "exact"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " 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."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "extend",
              "annotation": "string, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "One of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'zero'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'complex'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "; this determines how values "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n<0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are handled - by default they are 0, but it is possible to opt into the complex extension of the factorial (see below)."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The factorial of non-negative integer "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the product of all positive integers less than or equal to "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "n! = n * (n - 1) * (n - 2) * ... * 1",
          "execution_status": null
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/special/_basic.py",
  "item_line": 2939,
  "item_type": "function",
  "aliases": [
    "scipy.special.factorial"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.special import factorial\narr = np.array([3, 4, 5])\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "factorial(arr, exact=False)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "factorial(arr, exact=True)\nfactorial(5, exact=True)\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "exact",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "extend",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "zero"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "factorial"
  },
  "references": null,
  "qa": "scipy.special._basic:factorial",
  "arbitrary": [],
  "local_refs": [
    "exact",
    "extend",
    "n",
    "nf"
  ]
}