{
  "__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": "Z",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A linkage matrix containing the hierarchical clustering. 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 its structure."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Perform weighted/WPGMA linkage on the condensed 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": "y",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The upper triangular of the distance matrix. The result of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pdist"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is returned in this form."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "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 return structure and algorithm."
            }
          ]
        }
      ],
      "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": 334,
  "item_type": "function",
  "aliases": [
    "scipy.cluster.hierarchy.weighted"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.cluster.hierarchy import weighted, fcluster\nfrom scipy.spatial.distance import pdist\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFirst, we need a toy dataset to play with::\n\n    x x    x x\n    x        x\n\n    x        x\n    x x    x x\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "X = [[0, 0], [0, 1], [1, 0],\n     [0, 4], [0, 3], [1, 4],\n     [4, 0], [3, 0], [4, 1],\n     [4, 4], [3, 4], [4, 3]]\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThen, we get a condensed distance matrix from this dataset:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "y = pdist(X)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFinally, we can perform the clustering:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Z = weighted(y)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Z\n",
        "execution_status": "failure",
        "out": "array([[ 0.     ,  1.     ,  1.     ,  2.     ],\n       [ 6.     ,  7.     ,  1.     ,  2.     ],\n       [ 3.     ,  4.     ,  1.     ,  2.     ],\n       [ 9.     , 11.     ,  1.     ,  2.     ],\n       [ 2.     , 12.     ,  1.20711,  3.     ],\n       [ 8.     , 13.     ,  1.20711,  3.     ],\n       [ 5.     , 14.     ,  1.20711,  3.     ],\n       [10.     , 15.     ,  1.20711,  3.     ],\n       [18.     , 19.     ,  3.05596,  6.     ],\n       [16.     , 17.     ,  3.32379,  6.     ],\n       [20.     , 21.     ,  4.06358, 12.     ]])\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe linkage matrix ``Z`` represents a dendrogram - see\n`scipy.cluster.hierarchy.linkage` for a detailed explanation of its\ncontents.\n\nWe can use `scipy.cluster.hierarchy.fcluster` to see to which cluster\neach initial point would belong given a distance threshold:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fcluster(Z, 0.9, criterion='distance')\nfcluster(Z, 1.5, criterion='distance')\nfcluster(Z, 4, criterion='distance')\nfcluster(Z, 6, criterion='distance')\n",
        "execution_status": "success",
        "out": "array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=int32)\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAlso, `scipy.cluster.hierarchy.dendrogram` can be used to generate a\nplot of the dendrogram."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__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": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "for advanced creation of hierarchical clusterings."
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "scipy.spatial.distance.pdist",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "scipy.spatial.distance.pdist"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "pairwise distance metrics"
            }
          ]
        }
      ],
      "type": "func"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "y",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "weighted"
  },
  "references": null,
  "qa": "scipy.cluster.hierarchy._hierarchy_impl:weighted",
  "arbitrary": [],
  "local_refs": [
    "Z",
    "y"
  ]
}