{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "c80b2cef",
            "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": "f47491a7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\na = np.arange(16).reshape((4,4))\na",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0,  1,  2,  3],\n       [ 4,  5,  6,  7],\n       [ 8,  9, 10, 11],\n       [12, 13, 14, 15]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b98f32de",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "labels = np.zeros_like(a)\nlabels[:2,:2] = 1\nlabels[2:, 1:3] = 2\nlabels",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 1, 0, 0],\n       [1, 1, 0, 0],\n       [0, 2, 2, 0],\n       [0, 2, 2, 0]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c2b11afa",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import ndimage\nndimage.maximum(a)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "15"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "fe9426ea",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.maximum(a, labels=labels, index=[1,2])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "[5, 14]"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "475d88ea",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.maximum(a, labels=labels)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "14"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "648c6179",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b = np.array([[1, 2, 0, 0],\n              [5, 3, 0, 4],\n              [0, 0, 0, 7],\n              [9, 3, 0, 0]])\nlabels, labels_nb = ndimage.label(b)\nlabels",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 1, 0, 0],\n       [1, 1, 0, 2],\n       [0, 0, 0, 2],\n       [3, 3, 0, 0]], dtype=int32)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ea3ddb82",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.maximum(b, labels=labels, index=np.arange(1, labels_nb + 1))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "[5, 7, 9]"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}