{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "69b3222d",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "546d21be",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "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\nndimage.center_of_mass(a)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(2.0, 1.5)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "bbc1dd43",
            "cell_type": "markdown",
            "source": "Calculation of multiple objects in an image\n",
            "metadata": {}
        },
        {
            "id": "9eacdb5a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "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]\nndimage.center_of_mass(b, lbl, [1,2])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "[(0.33333333333333331, 1.3333333333333333), (3.5, 2.5)]"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "edb57a06",
            "cell_type": "markdown",
            "source": "Negative masses are also accepted, which can occur for example when\nbias is removed from measured data due to random noise.\n",
            "metadata": {}
        },
        {
            "id": "baeae3b8",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "c = np.array(([-1,0,0,0],\n              [0,-1,-1,0],\n              [0,1,-1,0],\n              [0,1,1,0]))\nndimage.center_of_mass(c)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(-4.0, 1.0)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "58becfa4",
            "cell_type": "markdown",
            "source": "If 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",
            "metadata": {}
        },
        {
            "id": "5cf43f00",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "d = np.array([-1, 1])\nndimage.center_of_mass(d)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(inf,)"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}