{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Arithmetic is modular when using integer types, and no error is raised on overflow."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The sum of an empty array is the neutral element 0:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> np.sum([])\n0.0",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For floating point numbers the numerical precision of sum (and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "np.add.reduce"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") is in general limited by directly adding each number individually to the result causing rounding errors in every step. However, often numpy will use a  numerically better approach (partial pairwise summation) leading to improved precision in many use-cases. This improved precision is always provided when no "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "axis"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is given. When "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "axis"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is given, it will depend on which axis is summed. Technically, to provide the best speed possible, the improved precision is only used when the summation is along the fast axis in memory. Note that the exact precision may vary depending on other parameters. In contrast to NumPy, Python's "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "math.fsum"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function uses a slower but more precise approach to summation. Especially when summing a large number of lower precision floating point numbers, such as "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "float32"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", numerical errors can become significant. In such cases it can be advisable to use "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "dtype=\"float64\"",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to use a higher precision for the output."
            }
          ]
        }
      ],
      "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": "sum_along_axis",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An array with the same shape as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", with the specified axis removed.   If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a 0-d array, or if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None, a scalar is returned.  If an output array is specified, a reference to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "out"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is returned."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Sum of array elements over a given axis."
            }
          ]
        }
      ],
      "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": "a",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Elements to sum."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "None or int or tuple of ints, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis or axes along which a sum is performed.  The default, axis=None, will sum all of the elements of the input array.  If axis is negative it counts from the last to the first axis. If axis is a tuple of ints, a sum is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "dtype",
              "annotation": "dtype, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The type of the returned array and of the accumulator in which the elements are summed.  The dtype of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is used by default unless "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has an integer dtype of less precision than the default platform integer.  In that case, if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is signed then the platform integer is used while if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is unsigned then an unsigned integer of the same precision as the platform integer is used."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "out",
              "annotation": "ndarray, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Alternative output array in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "keepdims",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If the default value is passed, then "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "keepdims"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will not be passed through to the "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sum",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "numpy:sum"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " method of sub-classes of "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "ndarray",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", however any non-default value will be.  If the sub-class' method does not implement "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "keepdims"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " any exceptions will be raised."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "initial",
              "annotation": "scalar, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Starting value for the sum. See "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~numpy.ufunc.reduce",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for details."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "where",
              "annotation": "array_like of bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Elements to include in the sum. See "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~numpy.ufunc.reduce",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for details."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "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": "/numpy/_core/fromnumeric.py",
  "item_line": 2304,
  "item_type": "_ArrayFunctionDispatcher",
  "aliases": [
    "numpy.sum"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.sum([0.5, 1.5])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.sum([[0, 1], [0, 5]])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.sum([[0, 1], [0, 5]], axis=0)\nnp.sum([[0, 1], [0, 5]], axis=1)\nnp.sum([[0, 1], [np.nan, 5]], where=[False, True], axis=1)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIf the accumulator is too small, overflow occurs:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.ones(128, dtype=np.int8).sum(dtype=np.int8)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nYou can also start the sum with a value other than zero:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.sum([10], initial=5)\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "add",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "add"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy.add.reduce"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " equivalent function."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "average",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "average"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "cumsum",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "cumsum"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Cumulative sum of array elements."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "mean",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "mean"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "ndarray.sum",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "ndarray.sum"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Equivalent method."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "trapezoid",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "trapezoid"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Integration of array values using composite trapezoidal rule."
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "a",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "dtype",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "out",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "keepdims",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "<no value>"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "initial",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "<no value>"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "where",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "<no value>"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "sum"
  },
  "references": null,
  "qa": "numpy:sum",
  "arbitrary": [],
  "local_refs": [
    "a",
    "axis",
    "dtype",
    "initial",
    "keepdims",
    "out",
    "sum_along_axis",
    "where"
  ]
}