{
  "__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": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "result",
              "annotation": "dok_array, coo_array, dict or ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Sparse matrix representing the results in \"dictionary of keys\" format. If a dict is returned the keys are "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(i,j)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " tuples of indices. If output_type is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'ndarray'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " a record array with fields "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'i'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'j'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'v'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is returned,"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute a sparse distance matrix"
            }
          ]
        }
      ],
      "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": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "other",
              "annotation": "cKDTree",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The other "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "KDTree",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.spatial._kdtree:KDTree"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to compute distances against."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "max_distance",
              "annotation": "positive float",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Maximum distance within which neighbors are returned. Distances above this value are returned as zero."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "p",
              "annotation": "float, 1<=p<=infinity",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Which Minkowski p-norm to use. A finite large p may cause a ValueError if overflow can occur."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "output_type",
              "annotation": "str, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Which container to use for output data. Options: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'dok_array'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'coo_array'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'dict'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'ndarray'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Legacy options "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'dok_matrix'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'coo_matrix'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are still available. Default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'dok_matrix'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "warning",
                  "base_type": "warning",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "warning "
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "dok_matrix and coo_matrix are being replaced. All new code using scipy sparse should use sparse array types 'dok_array' or 'coo_array'. The default value of "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "output_type"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " will be deprecated at v2.0 and switch from 'dok_matrix' to 'dok_array' in v2.2. The values 'dok_matrix' and 'coo_matrix' continue to work, but will go away eventually."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Computes a distance matrix between two cKDTrees, leaving as zero any distance greater than max_distance."
            }
          ]
        }
      ],
      "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": null,
  "item_line": null,
  "item_type": "cython_function_or_method",
  "aliases": [
    "scipy.spatial.cKDTree.sparse_distance_matrix"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "You can compute a sparse distance matrix between two kd-trees:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.spatial import cKDTree\nrng = np.random.default_rng()\npoints1 = rng.random((5, 2))\npoints2 = rng.random((5, 2))\nkdtree1 = cKDTree(points1)\nkdtree2 = cKDTree(points2)\nsdm = kdtree1.sparse_distance_matrix(kdtree2, 0.3, output_type=\"dok_array\")\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "sdm.toarray()\n",
        "execution_status": "failure",
        "out": "array([[0.     , 0.     , 0.11603, 0.     , 0.     ],\n       [0.     , 0.     , 0.     , 0.     , 0.     ],\n       [0.24287, 0.26248, 0.     , 0.     , 0.     ],\n       [0.     , 0.     , 0.13636, 0.     , 0.     ],\n       [0.     , 0.     , 0.     , 0.     , 0.     ]])\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nYou can check distances above the `max_distance` are zeros:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.spatial.distance import cdist\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "cdist(points1, points2)\n",
        "execution_status": "failure",
        "out": "array([[0.9595 , 0.8948 , 0.11603, 0.66051, 0.35869],\n       [0.42885, 0.56871, 0.71481, 0.68005, 0.40827],\n       [0.24287, 0.26248, 0.71725, 0.43233, 0.605  ],\n       [0.94969, 0.81421, 0.13636, 0.50014, 0.56379],\n       [1.06841, 0.87597, 0.38201, 0.50638, 0.8128 ]])\n"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "other",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "max_distance",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "p",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "2.0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "output_type",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "dok_matrix"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "sparse_distance_matrix"
  },
  "references": null,
  "qa": "scipy.spatial._ckdtree:cKDTree.sparse_distance_matrix",
  "arbitrary": [],
  "local_refs": [
    "max_distance",
    "other",
    "output_type",
    "p",
    "result"
  ]
}