{
  "__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": "results",
              "annotation": "set or ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Set of pairs "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(i,j)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "i < j"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", for which the corresponding positions are close. If output_type is 'ndarray', an ndarray is returned instead of a set."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Find all pairs of points in "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "self"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " whose distance is at most r."
            }
          ]
        }
      ],
      "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": "r",
              "annotation": "positive float",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The maximum distance."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "p",
              "annotation": "float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Which Minkowski norm to use.  "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has to meet the condition "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1 <= p <= infinity"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "eps",
              "annotation": "float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Approximate search.  Branches of the tree are not explored if their nearest points are further than "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "r/(1+eps)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", and branches are added in bulk if their furthest points are nearer than "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "r * (1+eps)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".  "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "eps"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has to be non-negative."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "output_type",
              "annotation": "str, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Choose the output container, 'set' or 'ndarray'. Default: 'set'"
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionadded",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionadded 1.6.0"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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": "build-install/usr/lib/python3.14/site-packages/scipy/spatial/_kdtree.py",
  "item_line": 692,
  "item_type": "function",
  "aliases": [
    "scipy.spatial.KDTree.query_pairs"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "You can search all pairs of points in a kd-tree within a distance:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.spatial import KDTree\nrng = np.random.default_rng()\npoints = rng.random((20, 2))\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.figure(figsize=(6, 6))\nplt.plot(points[:, 0], points[:, 1], \"xk\", markersize=14)\n",
        "execution_status": "failure",
        "out": "[<matplotlib.lines.Line2D object at 0x7f3f68aecd70>]\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "kd_tree = KDTree(points)\npairs = kd_tree.query_pairs(r=0.2)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "for (i, j) in pairs:\n    plt.plot([points[i, 0], points[j, 0]],\n            [points[i, 1], points[j, 1]], \"-r\")\n",
        "execution_status": "failure",
        "out": "[<matplotlib.lines.Line2D object at 0x7f3f68aec2f0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aec830>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aedbe0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aed160>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aee510>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aedfd0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aef0e0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aeecf0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aef380>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aee660>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aefe00>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aee3c0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aec6e0>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aef230>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aefb60>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aed400>]\n[<matplotlib.lines.Line2D object at 0x7f3f68aecc20>]\n[<matplotlib.lines.Line2D object at 0x7f3f59b11d30>]\n[<matplotlib.lines.Line2D object at 0x7f3f59b13b60>]\n[<matplotlib.lines.Line2D object at 0x7f3f59b10440>]\n[<matplotlib.lines.Line2D object at 0x7f3f59b12120>]\n[<matplotlib.lines.Line2D object at 0x7f3f59b11550>]\n[<matplotlib.lines.Line2D object at 0x7f3f59b13620>]\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-ad99bf26f296f93c.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "self",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "r",
        "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": "eps",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "0.0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "output_type",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "set"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "query_pairs"
  },
  "references": null,
  "qa": "scipy.spatial._kdtree:KDTree.query_pairs",
  "arbitrary": [],
  "local_refs": [
    "eps",
    "output_type",
    "p",
    "r",
    "results"
  ]
}