{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "e01fd7d8",
            "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": "cd08ffab",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from io import StringIO\nfrom scipy.io import mmread",
            "outputs": []
        },
        {
            "id": "59100393",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "text = '''%%MatrixMarket matrix coordinate real general\n 5 5 7\n 2 3 1.0\n 3 4 2.0\n 3 5 3.0\n 4 1 4.0\n 4 2 5.0\n 4 3 6.0\n 4 4 7.0\n'''",
            "outputs": []
        },
        {
            "id": "8a772538",
            "cell_type": "markdown",
            "source": "``mmread(source)`` returns the data as sparse array in COO format.\n",
            "metadata": {}
        },
        {
            "id": "edcd82a0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m = mmread(StringIO(text), spmatrix=False)\nm",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "<COOrdinate sparse array of dtype 'float64'\n    with 7 stored elements and shape (5, 5)>"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "edb2c8c7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m.toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0., 0., 0., 0., 0.],\n       [0., 0., 1., 0., 0.],\n       [0., 0., 0., 2., 3.],\n       [4., 5., 6., 7., 0.],\n       [0., 0., 0., 0., 0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "a38abe25",
            "cell_type": "markdown",
            "source": "This method is threaded.\nThe default number of threads is equal to the number of CPUs in the system.\nUse [threadpoolctl](https://github.com/joblib/threadpoolctl) to override:\n",
            "metadata": {}
        },
        {
            "id": "4abb9afa",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import threadpoolctl\n\nwith threadpoolctl.threadpool_limits(limits=2):\n    m = mmread(StringIO(text), spmatrix=False)",
            "outputs": []
        }
    ]
}