{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "61697ed1",
            "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": "262cdf97",
            "cell_type": "markdown",
            "source": "Create an array of 10 values and trim 10% of those values from each end:\n",
            "metadata": {}
        },
        {
            "id": "555844d8",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import stats\na = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\nstats.trimboth(a, 0.1)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([1, 3, 2, 4, 5, 6, 7, 8])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b62ea553",
            "cell_type": "markdown",
            "source": "Note that the elements of the input array are trimmed by value, but the\noutput array is not necessarily sorted.\n\nThe proportion to trim is rounded down to the nearest integer. For\ninstance, trimming 25% of the values from each end of an array of 10\nvalues will return an array of 6 values:\n",
            "metadata": {}
        },
        {
            "id": "e3fd252d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b = np.arange(10)\nstats.trimboth(b, 1/4).shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(6,)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "065c5660",
            "cell_type": "markdown",
            "source": "Multidimensional arrays can be trimmed along any axis or across the entire\narray:\n",
            "metadata": {}
        },
        {
            "id": "32727431",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "c = [2, 4, 6, 8, 0, 1, 3, 5, 7, 9]\nd = np.array([a, b, c])\nstats.trimboth(d, 0.4, axis=0).shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(1, 10)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b6a02175",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "stats.trimboth(d, 0.4, axis=1).shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(3, 2)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "57e08e86",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "stats.trimboth(d, 0.4, axis=None).shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(6,)"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}