{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "f2943d07",
            "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": "01baa3b8",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import stats",
            "outputs": []
        },
        {
            "id": "11209200",
            "cell_type": "markdown",
            "source": "Calculate the counts with explicit bin-edges:\n",
            "metadata": {}
        },
        {
            "id": "00267653",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = [0.1, 0.1, 0.1, 0.6]\ny = [2.1, 2.6, 2.1, 2.1]\nbinx = [0.0, 0.5, 1.0]\nbiny = [2.0, 2.5, 3.0]\nret = stats.binned_statistic_2d(x, y, None, 'count', bins=[binx, biny])\nret.statistic",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[2., 1.],\n       [1., 0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "a2e41a21",
            "cell_type": "markdown",
            "source": "The bin in which each sample is placed is given by the `binnumber`\nreturned parameter.  By default, these are the linearized bin indices:\n",
            "metadata": {}
        },
        {
            "id": "057a2cd7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ret.binnumber",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([5, 6, 5, 9])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1c957788",
            "cell_type": "markdown",
            "source": "The bin indices can also be expanded into separate entries for each\ndimension using the `expand_binnumbers` parameter:\n",
            "metadata": {}
        },
        {
            "id": "4a6a616b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ret = stats.binned_statistic_2d(x, y, None, 'count', bins=[binx, biny],\n                                expand_binnumbers=True)\nret.binnumber",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 1, 1, 2],\n       [1, 2, 1, 1]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c1e49ecb",
            "cell_type": "markdown",
            "source": "Which shows that the first three elements belong in the xbin 1, and the\nfourth into xbin 2; and so on for y.",
            "metadata": {}
        }
    ]
}