{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "23443192",
            "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": "0b9f3ac6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.stats import randint\nimport matplotlib.pyplot as plt\nfig, ax = plt.subplots(1, 1)",
            "outputs": []
        },
        {
            "id": "cc418cf9",
            "cell_type": "markdown",
            "source": "Calculate the first four moments:\n",
            "metadata": {}
        },
        {
            "id": "7c1a0206",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "low, high = 7, 31\nmean, var, skew, kurt = randint.stats(low, high, moments='mvsk')",
            "outputs": []
        },
        {
            "id": "c21fb6a3",
            "cell_type": "markdown",
            "source": "Display the probability mass function (``pmf``):\n",
            "metadata": {}
        },
        {
            "id": "b4af4d57",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.arange(low - 5, high + 5)\nax.plot(x, randint.pmf(x, low, high), 'bo', ms=8, label='randint pmf')\nax.vlines(x, 0, randint.pmf(x, low, high), colors='b', lw=5, alpha=0.5)",
            "outputs": []
        },
        {
            "id": "21599797",
            "cell_type": "markdown",
            "source": "Alternatively, the distribution object can be called (as a function) to\nfix the shape and location. This returns a \"frozen\" RV object holding the\ngiven parameters fixed.\n\nFreeze the distribution and display the frozen ``pmf``:\n",
            "metadata": {}
        },
        {
            "id": "06815f59",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "rv = randint(low, high)\nax.vlines(x, 0, rv.pmf(x), colors='k', linestyles='-',\n          lw=1, label='frozen pmf')\nax.legend(loc='lower center')\nplt.show()",
            "outputs": []
        },
        {
            "id": "46f1f5fc",
            "cell_type": "markdown",
            "source": "Check the relationship between the cumulative distribution function\n(``cdf``) and its inverse, the percent point function (``ppf``):\n",
            "metadata": {}
        },
        {
            "id": "e1353fc2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "q = np.arange(low, high)\np = randint.cdf(q, low, high)\nnp.allclose(q, randint.ppf(p, low, high))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "938644ec",
            "cell_type": "markdown",
            "source": "Generate random numbers:\n",
            "metadata": {}
        },
        {
            "id": "096bb5c4",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = randint.rvs(low, high, size=1000)",
            "outputs": []
        }
    ]
}