{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "a458f180",
            "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": "d1d08185",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.sparse import csr_array, diags_array\nimport numpy as np\nfrom scipy.sparse.linalg import norm\na = np.arange(9) - 4\na",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-4, -3, -2, -1, 0, 1, 2, 3, 4])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "8af8fdaf",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b = a.reshape((3, 3))\nb",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[-4, -3, -2],\n       [-1, 0, 1],\n       [ 2, 3, 4]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "be1dab96",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b = csr_array(b)\nnorm(b)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "7.745966692414834"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d8de85a2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "norm(b, 'fro')",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "7.745966692414834"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "acfcc2d3",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "norm(b, np.inf)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "9"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "398279b9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "norm(b, -np.inf)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "2"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "97f93db6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "norm(b, 1)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "7"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d1a256e7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "norm(b, -1)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "6"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c6938850",
            "cell_type": "markdown",
            "source": "The matrix 2-norm or the spectral norm is the largest singular\nvalue, computed approximately and with limitations.\n",
            "metadata": {}
        },
        {
            "id": "67b688c9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b = diags_array([-1, 1], offsets=[0, 1], shape=(9, 10))\nnorm(b, 2)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "1.9753..."
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}