{
  "__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": "tree",
              "annotation": "ClusterNode or tuple (ClusterNode, list of ClusterNode)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rd"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False, a "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "ClusterNode",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rd"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True, a list of length "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "2*n - 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " the number of samples.  See the description of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rd"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " above for more details."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Convert a linkage matrix into an easy-to-use tree object."
            }
          ]
        }
      ],
      "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": "Z",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The linkage matrix in proper form (see the "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "linkage",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.cluster.hierarchy._hierarchy_impl:linkage"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function documentation)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rd",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When False (default), a reference to the root "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "ClusterNode",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " object is returned.  Otherwise, a tuple "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(r, d)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is returned. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "r"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a reference to the root node while "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "d"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a list of "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "ClusterNode",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " objects - one per original entry in the linkage matrix plus entries for all clustering steps. If a cluster id is less than the number of samples "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the data that the linkage matrix describes, then it corresponds to a singleton cluster (leaf node). See "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "linkage",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.cluster.hierarchy._hierarchy_impl:linkage"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for more information on the assignment of cluster ids to clusters."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The reference to the root "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ClusterNode",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " object is returned (by default)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Each "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ClusterNode",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " object has a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "left"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "right"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dist"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "id"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "count"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute. The left and right attributes point to ClusterNode objects that were combined to generate the cluster. If both are None then the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ClusterNode",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " object is a leaf node, its count must be 1, and its distance is meaningless but set to 0."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Note: This function is provided for the convenience of the library\nuser. ClusterNodes are not used as input to any of the functions in this\nlibrary."
                }
              ]
            }
          ]
        }
      ],
      "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/cluster/hierarchy/_hierarchy_impl.py",
  "item_line": 1304,
  "item_type": "function",
  "aliases": [
    "scipy.cluster.hierarchy.to_tree"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.cluster import hierarchy\nrng = np.random.default_rng()\nx = rng.random((5, 2))\nZ = hierarchy.linkage(x)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "hierarchy.to_tree(Z)\n",
        "execution_status": "failure",
        "out": "<scipy.cluster.hierarchy._hierarchy_impl.ClusterNode object at 0x7f3f434647c0>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rootnode, nodelist = hierarchy.to_tree(Z, rd=True)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rootnode\n",
        "execution_status": "failure",
        "out": "<scipy.cluster.hierarchy._hierarchy_impl.ClusterNode object at 0x7f3f43464e50>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "len(nodelist)\n",
        "execution_status": "success",
        "out": "9\n"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "ClusterNode",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.cluster.hierarchy._hierarchy_impl:ClusterNode"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "is_valid_linkage",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.cluster.hierarchy._hierarchy_impl:is_valid_linkage"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "linkage",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.cluster.hierarchy._hierarchy_impl:linkage"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "Z",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rd",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "to_tree"
  },
  "references": null,
  "qa": "scipy.cluster.hierarchy._hierarchy_impl:to_tree",
  "arbitrary": [],
  "local_refs": [
    "Z",
    "rd",
    "tree"
  ]
}