{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "fb6c595e",
            "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": "d0dc3df1",
            "cell_type": "markdown",
            "source": "Suppose we have a normally distributed random variable $X$:\n",
            "metadata": {}
        },
        {
            "id": "00ebe1aa",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import stats\nX = stats.Normal()",
            "outputs": []
        },
        {
            "id": "ec754902",
            "cell_type": "markdown",
            "source": "We wish to have a random variable $Y$ distributed according to\nthe folded normal distribution; that is, a random variable $|X|$.\n",
            "metadata": {}
        },
        {
            "id": "0784ef64",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "Y = stats.abs(X)",
            "outputs": []
        },
        {
            "id": "af4892be",
            "cell_type": "markdown",
            "source": "The PDF of the distribution in the left half plane is \"folded\" over to\nthe right half plane. Because the normal PDF is symmetric, the resulting\nPDF is zero for negative arguments and doubled for positive arguments.\n",
            "metadata": {}
        },
        {
            "id": "d8e636a5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nx = np.linspace(0, 5, 300)\nax = plt.gca()\nY.plot(x='x', y='pdf', t=('x', -1, 5), ax=ax)\nplt.plot(x, 2 * X.pdf(x), '--')\nplt.legend(('PDF of `Y`', 'Doubled PDF of `X`'))\nplt.show()",
            "outputs": []
        }
    ]
}