{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "d573156b",
            "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": "b37e2f52",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.special import softmax\nnp.set_printoptions(precision=5)",
            "outputs": []
        },
        {
            "id": "a2dca9fa",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.array([[1, 0.5, 0.2, 3],\n              [1,  -1,   7, 3],\n              [2,  12,  13, 3]])\n",
            "outputs": []
        },
        {
            "id": "7837c562",
            "cell_type": "markdown",
            "source": "Compute the softmax transformation over the entire array.\n",
            "metadata": {}
        },
        {
            "id": "c2915ccd",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m = softmax(x)\nm",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[  4.48309e-06,   2.71913e-06,   2.01438e-06,   3.31258e-05],\n       [  4.48309e-06,   6.06720e-07,   1.80861e-03,   3.31258e-05],\n       [  1.21863e-05,   2.68421e-01,   7.29644e-01,   3.31258e-05]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e40371ec",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m.sum()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "1.0"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "17677352",
            "cell_type": "markdown",
            "source": "Compute the softmax transformation along the first axis (i.e., the\ncolumns).\n",
            "metadata": {}
        },
        {
            "id": "a67ee3b9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m = softmax(x, axis=0)",
            "outputs": []
        },
        {
            "id": "ed1abae8",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[  2.11942e-01,   1.01300e-05,   2.75394e-06,   3.33333e-01],\n       [  2.11942e-01,   2.26030e-06,   2.47262e-03,   3.33333e-01],\n       [  5.76117e-01,   9.99988e-01,   9.97525e-01,   3.33333e-01]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "39e5d524",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m.sum(axis=0)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.,  1.,  1.,  1.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c5a8e546",
            "cell_type": "markdown",
            "source": "Compute the softmax transformation along the second axis (i.e., the rows).\n",
            "metadata": {}
        },
        {
            "id": "8f49b0b5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m = softmax(x, axis=1)\nm",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[  1.05877e-01,   6.42177e-02,   4.75736e-02,   7.82332e-01],\n       [  2.42746e-03,   3.28521e-04,   9.79307e-01,   1.79366e-02],\n       [  1.22094e-05,   2.68929e-01,   7.31025e-01,   3.31885e-05]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c98a7a35",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m.sum(axis=1)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.,  1.,  1.])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}