{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "48f7bbcf",
            "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": "0d477a3c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.sparse import csr_array, triu\nA = csr_array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]],\n               dtype='int32')\nA.toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 2, 0, 0, 3],\n       [4, 5, 0, 6, 7],\n       [0, 0, 8, 9, 0]], dtype=int32)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d5291b06",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "triu(A).toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 2, 0, 0, 3],\n       [0, 5, 0, 6, 7],\n       [0, 0, 8, 9, 0]], dtype=int32)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "819ef249",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "triu(A).nnz",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "8"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "4f0d246e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "triu(A, k=1).toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0, 2, 0, 0, 3],\n       [0, 0, 0, 6, 7],\n       [0, 0, 0, 9, 0]], dtype=int32)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "0ee929d2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "triu(A, k=-1).toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 2, 0, 0, 3],\n       [4, 5, 0, 6, 7],\n       [0, 0, 8, 9, 0]], dtype=int32)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b08d315f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "triu(A, format='csc')",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "<Compressed Sparse Column sparse array of dtype 'int32'\n    with 8 stored elements and shape (3, 5)>"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}