{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "No Docstrings"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/sparse/__init__.py",
  "item_line": 0,
  "item_type": "module",
  "aliases": [
    "scipy.sparse"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "scipy.sparse",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sparse.csgraph",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "sparse.csgraph"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sparse.linalg",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "sparse.linalg"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sparse.migration_to_sparray",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "sparse.migration_to_sparray"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy 2-D sparse array package for numeric data."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "This package is switching to an array interface, compatible with NumPy arrays, from the older matrix interface.  We recommend that you use the array objects ("
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "bsr_array",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "module",
                    "path": "scipy.sparse._bsr:bsr_array"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "coo_array",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "module",
                    "path": "scipy.sparse._coo:coo_array"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", etc.) for all new work."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "When using the array interface, please note that:"
                }
              ]
            },
            {
              "__type": "BulletList",
              "__tag": 4053,
              "ordered": false,
              "start": 1,
              "children": [
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "x * y"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " no longer performs matrix multiplication, but   element-wise multiplication (just like with NumPy arrays).  To   make code work with both arrays and matrices, use "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "x @ y"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " for   matrix multiplication."
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Operations such as "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "sum"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": ", that used to produce dense matrices, now   produce arrays, whose multiplication behavior differs similarly."
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Sparse arrays use array style "
                        },
                        {
                          "__type": "Emphasis",
                          "__tag": 4047,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "slicing"
                            }
                          ]
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " operations, returning scalars,   1D, or 2D sparse arrays. If you need 2D results, use an appropriate index.   E.g. "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "A[:, i, None]"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " or "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "A[:, [i]]"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "."
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "All index arrays for a given sparse array should be of same dtype.   For example, for CSR format, "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "indices"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " and "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "indptr"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " should have   the same dtype. For COO, each array in "
                        },
                        {
                          "__type": "InlineRole",
                          "__tag": 4003,
                          "value": "coords",
                          "domain": null,
                          "role": null,
                          "inventory": null
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " should have same dtype."
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The construction utilities ("
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "eye",
                  "domain": null,
                  "role": null,
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "kron",
                  "domain": null,
                  "role": null,
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "random",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "random",
                    "version": "*",
                    "kind": "api",
                    "path": "random"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "diags",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "module",
                    "path": "scipy.sparse._construct:diags"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", etc.) have appropriate replacements (see "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "sparse-construction-functions",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ")."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "For more information see "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "Migration from spmatrix to sparray <migration_to_sparray>",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Sparse arrays ("
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "scipy.sparse",
          "domain": null,
          "role": "mod",
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": ")"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    csgraph - Compressed sparse graph routines\n    linalg - Sparse linear algebra routines",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Submodules"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    bsr_array - Block Sparse Row array\n    coo_array - A sparse array in COOrdinate format\n    csc_array - Compressed Sparse Column array\n    csr_array - Compressed Sparse Row array\n    dia_array - Sparse array with DIAgonal storage\n    dok_array - Dictionary Of Keys based sparse array\n    lil_array - Row-based list of lists sparse array\n    sparray - Sparse array base class",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Sparse array classes"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    diags_array - Return a sparse array from diagonals\n    eye_array - Sparse MxN array whose k-th diagonal is all ones\n    random_array - Random values in a given shape array\n    block_array - Build a sparse array from sub-blocks",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building sparse arrays"
        }
      ],
      "level": 2,
      "target": "sparse-construction-functions"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    kron - Kronecker product of two sparse arrays\n    kronsum - Kronecker sum of sparse arrays\n    block_diag - Build a block diagonal sparse array\n    tril - Lower triangular portion of a sparse array\n    triu - Upper triangular portion of a sparse array\n    hstack - Stack sparse arrays horizontally (column wise)\n    vstack - Stack sparse arrays vertically (row wise)\n    swapaxes - swap two axes of a sparse array\n    expand_dims - add a new (trivial) axis to a sparse array\n    permute_dims - reorder the axes of a sparse array",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Combining arrays"
        }
      ],
      "level": 2,
      "target": "combining-arrays"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    save_npz - Save a sparse array to a file using ``.npz`` format.\n    load_npz - Load a sparse array from a file using ``.npz`` format.\n    find - Return the indices and values of the nonzero elements\n    get_index_dtype - determine a good dtype for index arrays.\n    safely_cast_index_arrays - cast index array dtype or raise if shape too big",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Sparse tools"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    issparse - Check if the argument is a sparse object (array or matrix).",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Identifying sparse arrays"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    bsr_matrix - Block Sparse Row matrix\n    coo_matrix - A sparse matrix in COOrdinate format\n    csc_matrix - Compressed Sparse Column matrix\n    csr_matrix - Compressed Sparse Row matrix\n    dia_matrix - Sparse matrix with DIAgonal storage\n    dok_matrix - Dictionary Of Keys based sparse matrix\n    lil_matrix - Row-based list of lists sparse matrix\n    spmatrix - Sparse matrix base class",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Sparse matrix classes"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    eye - Sparse MxN matrix whose k-th diagonal is all ones\n    identity - Identity matrix in sparse matrix format\n    diags - Return a sparse matrix from diagonals\n    spdiags - Return a sparse matrix from diagonals\n    bmat - Build a sparse matrix from sparse sub-blocks\n    random - Random values in a given shape matrix\n    rand - Random values in a given shape matrix (old interface)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Combining matrices use the same functions as for"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "combining-arrays",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building sparse matrices"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    issparse\n    isspmatrix\n    isspmatrix_csc\n    isspmatrix_csr\n    isspmatrix_bsr\n    isspmatrix_lil\n    isspmatrix_dok\n    isspmatrix_coo\n    isspmatrix_dia",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Identifying sparse matrices"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ".. autosummary:: \n    :toctree:generated/\n    SparseEfficiencyWarning\n    SparseWarning",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Warnings"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are seven available sparse array types:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "BulletList",
              "__tag": 4053,
              "ordered": true,
              "start": 1,
              "children": [
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "csc_array: Compressed Sparse Column format"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "csr_array: Compressed Sparse Row format"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "bsr_array: Block Sparse Row format"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "lil_array: List of Lists format"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "dok_array: Dictionary of Keys format"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "coo_array: COOrdinate format (aka IJV, triplet format)"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "ListItem",
                  "__tag": 4054,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "dia_array: DIAgonal format"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To construct an array efficiently, use any of "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "coo_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._coo:coo_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "dok_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._dok:dok_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lil_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._lil:lil_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "dok_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._dok:dok_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lil_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._lil:lil_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " support basic slicing and fancy indexing with a similar syntax to NumPy arrays. The COO format does not support indexing (yet) but can also be used to efficiently construct arrays using coord and value info."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Despite their similarity to NumPy arrays, it is "
            },
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "strongly discouraged"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to use NumPy functions directly on these arrays because NumPy typically treats them as generic Python objects rather than arrays, leading to unexpected (and incorrect) results. If you do want to apply a NumPy function to these arrays, first check if SciPy has its own implementation for the given sparse array class, or "
            },
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "convert the sparse array to\na NumPy array"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (e.g., using the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "toarray",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method of the class) before applying the method."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "All conversions among the CSR, CSC, and COO formats are efficient, linear-time operations."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To perform manipulations such as multiplication or inversion, first convert the array to either CSC or CSR format. The "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lil_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._lil:lil_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " format is row-based, so conversion to CSR is efficient, whereas conversion to CSC is less so."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Usage information"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To do a vector product between a 2D sparse array and a vector use the matmul operator (i.e., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "@"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") which performs a dot product (like the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dot"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method):"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import numpy as np\n>>> from scipy.sparse import csr_array\n>>> A = csr_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])\n>>> v = np.array([1, 0, -1])\n>>> A @ v\narray([ 1, -3, -1], dtype=int64)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The CSR format is especially suitable for fast matrix vector products."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Matrix vector product"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Construct a 1000x1000 "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lil_array",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.sparse._lil:lil_array"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and add some values to it:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.sparse import lil_array\n>>> from scipy.sparse.linalg import spsolve\n>>> from numpy.linalg import solve, norm\n>>> from numpy.random import rand",
          "execution_status": null
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> A = lil_array((1000, 1000))\n>>> A[0, :100] = rand(100)\n>>> A.setdiag(rand(1000))",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now convert it to CSR format and solve A x = b for x:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> A = A.tocsr()\n>>> b = rand(1000)\n>>> x = spsolve(A, b)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Convert it to a dense array and solve, and check that the result is the same:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x_ = solve(A.toarray(), b)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now we can compute norm of the error with:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> err = norm(x-x_)\n>>> err < 1e-9\nTrue",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "It should be small :)"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Example 1"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Construct an array in COO format:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy import sparse\n>>> from numpy import array\n>>> I = array([0,3,1,0])\n>>> J = array([0,3,1,2])\n>>> V = array([4,5,7,9])\n>>> A = sparse.coo_array((V,(I,J)),shape=(4,4))",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Notice that the indices do not need to be sorted."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Duplicate (i,j) entries are summed when converting to CSR or CSC."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> I = array([0,0,1,3,1,0,0])\n>>> J = array([0,2,1,3,1,0,0])\n>>> V = array([1,1,1,1,1,1,1])\n>>> B = sparse.coo_array((V,(I,J)),shape=(4,4)).tocsr()",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This is useful for constructing finite-element stiffness and mass matrices."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Example 2"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "CSR column indices are not necessarily sorted. Likewise for CSC row indices. Use the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".sorted_indices()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".sort_indices()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " methods when sorted indices are required (e.g., when passing data to other libraries)."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Further details"
        }
      ],
      "level": 2,
      "target": null
    }
  ],
  "local_refs": []
}