{
  "__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": "Abstract linear algebra library."
            }
          ]
        }
      ],
      "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": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This module defines a class hierarchy that implements a kind of \"lazy\" matrix representation, called the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "LinearOperator"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". It can be used to do linear algebra with extremely large sparse or structured matrices, without representing those explicitly in memory. Such matrices can be added, multiplied, transposed, etc."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As a motivating example, suppose you want have a matrix where almost all of the elements have the value one. The standard sparse matrix representation skips the storage of zeros, but not ones. By contrast, a LinearOperator is able to represent such matrices efficiently. First, we need a compact way to represent an all-ones matrix      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import numpy as np\n>>> from scipy.sparse.linalg._interface import LinearOperator\n>>> class Ones(LinearOperator):\n...     def __init__(self, shape):\n...         super().__init__(dtype=None, shape=shape)\n...     def _matvec(self, x):\n...         return np.repeat(x.sum(), self.shape[0])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Instances of this class emulate "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "np.ones(shape)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", but using a constant amount of storage, independent of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_matvec"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method specifies how this linear operator multiplies with (operates on) a vector. We can now add this operator to a sparse matrix that stores only offsets from one      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.sparse.linalg._interface import aslinearoperator\n>>> from scipy.sparse import csr_array\n>>> offsets = csr_array([[1, 0, 2], [0, -1, 0], [0, 0, 3]])\n>>> A = aslinearoperator(offsets) + Ones(offsets.shape)\n>>> A.dot([1, 2, 3])\narray([13,  4, 15])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The result is the same as that given by its dense, explicitly-stored counterpart      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> (np.ones(A.shape, A.dtype) + offsets.toarray()).dot([1, 2, 3])\narray([13,  4, 15])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Several algorithms in the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scipy.sparse"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " library are able to operate on "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "LinearOperator"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " instances."
            }
          ]
        }
      ],
      "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/linalg/_interface.py",
  "item_line": 0,
  "item_type": "module",
  "aliases": [
    "scipy.sparse.linalg._interface"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "scipy.sparse.linalg._interface",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Abstract linear algebra library."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This module defines a class hierarchy that implements a kind of \"lazy\" matrix representation, called the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "LinearOperator"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". It can be used to do linear algebra with extremely large sparse or structured matrices, without representing those explicitly in memory. Such matrices can be added, multiplied, transposed, etc."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As a motivating example, suppose you want have a matrix where almost all of the elements have the value one. The standard sparse matrix representation skips the storage of zeros, but not ones. By contrast, a LinearOperator is able to represent such matrices efficiently. First, we need a compact way to represent an all-ones matrix      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import numpy as np\n>>> from scipy.sparse.linalg._interface import LinearOperator\n>>> class Ones(LinearOperator):\n...     def __init__(self, shape):\n...         super().__init__(dtype=None, shape=shape)\n...     def _matvec(self, x):\n...         return np.repeat(x.sum(), self.shape[0])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Instances of this class emulate "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "np.ones(shape)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", but using a constant amount of storage, independent of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "shape"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_matvec"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method specifies how this linear operator multiplies with (operates on) a vector. We can now add this operator to a sparse matrix that stores only offsets from one      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.sparse.linalg._interface import aslinearoperator\n>>> from scipy.sparse import csr_array\n>>> offsets = csr_array([[1, 0, 2], [0, -1, 0], [0, 0, 3]])\n>>> A = aslinearoperator(offsets) + Ones(offsets.shape)\n>>> A.dot([1, 2, 3])\narray([13,  4, 15])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The result is the same as that given by its dense, explicitly-stored counterpart      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> (np.ones(A.shape, A.dtype) + offsets.toarray()).dot([1, 2, 3])\narray([13,  4, 15])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Several algorithms in the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scipy.sparse"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " library are able to operate on "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "LinearOperator"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " instances."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    }
  ],
  "local_refs": []
}