{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "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": "center_of_mass",
              "annotation": "tuple, or list of tuples",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Coordinates of centers-of-mass."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Calculate the center of mass of the values of an array at labels."
            }
          ]
        }
      ],
      "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": "input",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Data from which to calculate center-of-mass. The masses can either be positive or negative."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "labels",
              "annotation": "ndarray, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Labels for objects in "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "input"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", as generated by "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "ndimage.label",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Only used with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "index"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Dimensions must be the same as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "input"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "index",
              "annotation": "int or sequence of ints, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Labels for which to calculate centers-of-mass. If not specified, the combined center of mass of all labels greater than zero will be calculated. Only used with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "labels"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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": "build-install/usr/lib/python3.14/site-packages/scipy/ndimage/_measurements.py",
  "item_line": 1485,
  "item_type": "function",
  "aliases": [
    "scipy.ndimage.center_of_mass"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\na = np.array(([0,0,0,0],\n              [0,1,1,0],\n              [0,1,1,0],\n              [0,1,1,0]))\nfrom scipy import ndimage\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ndimage.center_of_mass(a)\n",
        "execution_status": "failure",
        "out": "(np.float64(2.0), np.float64(1.5))\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCalculation of multiple objects in an image\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "b = np.array(([0,1,1,0],\n              [0,1,0,0],\n              [0,0,0,0],\n              [0,0,1,1],\n              [0,0,1,1]))\nlbl = ndimage.label(b)[0]\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ndimage.center_of_mass(b, lbl, [1,2])\n",
        "execution_status": "failure",
        "out": "[(np.float64(0.3333333333333333), np.float64(1.3333333333333333)), (np.float64(3.5), np.float64(2.5))]\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNegative masses are also accepted, which can occur for example when\nbias is removed from measured data due to random noise.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "c = np.array(([-1,0,0,0],\n              [0,-1,-1,0],\n              [0,1,-1,0],\n              [0,1,1,0]))\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ndimage.center_of_mass(c)\n",
        "execution_status": "failure",
        "out": "(np.float64(-4.0), np.float64(1.0))\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIf there are division by zero issues, the function does not raise an\nerror but rather issues a RuntimeWarning before returning inf and/or NaN.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "d = np.array([-1, 1])\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ndimage.center_of_mass(d)\n",
        "execution_status": "failure",
        "out": "(np.float64(inf),)\n"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "input",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "labels",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "index",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "center_of_mass"
  },
  "references": null,
  "qa": "scipy.ndimage._measurements:center_of_mass",
  "arbitrary": [],
  "local_refs": [
    "center_of_mass",
    "index",
    "input",
    "labels"
  ]
}