{
  "__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": "to_mlab_linkage",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A linkage matrix compatible with MATLAB(TM)'s hierarchical clustering functions."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The return linkage matrix has the last column removed and the cluster indices are converted to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1..N"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " indexing."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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 to a MATLAB(TM) compatible one."
            }
          ]
        }
      ],
      "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": "A linkage matrix generated by "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "scipy.cluster.hierarchy"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Converts a linkage matrix "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "Z"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " generated by the linkage function of this module to a MATLAB(TM) compatible one. The return linkage matrix has the last column removed and the cluster indices are converted to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "1..N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " indexing."
            }
          ]
        }
      ],
      "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": 1819,
  "item_type": "function",
  "aliases": [
    "scipy.cluster.hierarchy.to_mlab_linkage"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.cluster.hierarchy import ward, to_mlab_linkage\nfrom scipy.spatial.distance import pdist\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\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": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Z = ward(pdist(X))\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Z\n",
        "execution_status": "failure",
        "out": "array([[ 0.     ,  1.     ,  1.     ,  2.     ],\n       [ 3.     ,  4.     ,  1.     ,  2.     ],\n       [ 6.     ,  7.     ,  1.     ,  2.     ],\n       [ 9.     , 10.     ,  1.     ,  2.     ],\n       [ 2.     , 12.     ,  1.29099,  3.     ],\n       [ 5.     , 13.     ,  1.29099,  3.     ],\n       [ 8.     , 14.     ,  1.29099,  3.     ],\n       [11.     , 15.     ,  1.29099,  3.     ],\n       [16.     , 17.     ,  5.7735 ,  6.     ],\n       [18.     , 19.     ,  5.7735 ,  6.     ],\n       [20.     , 21.     ,  8.16497, 12.     ]])\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAfter a linkage matrix ``Z`` has been created, we can use\n`scipy.cluster.hierarchy.to_mlab_linkage` to convert it\ninto MATLAB format:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "mZ = to_mlab_linkage(Z)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "mZ\n",
        "execution_status": "failure",
        "out": "array([[ 1.     ,  2.     ,  1.     ],\n       [ 4.     ,  5.     ,  1.     ],\n       [ 7.     ,  8.     ,  1.     ],\n       [10.     , 11.     ,  1.     ],\n       [ 3.     , 13.     ,  1.29099],\n       [ 6.     , 14.     ,  1.29099],\n       [ 9.     , 15.     ,  1.29099],\n       [12.     , 16.     ,  1.29099],\n       [17.     , 18.     ,  5.7735 ],\n       [19.     , 20.     ,  5.7735 ],\n       [21.     , 22.     ,  8.16497]])\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe new linkage matrix ``mZ`` uses 1-indexing for all the\nclusters (instead of 0-indexing). Also, the last column of\nthe original linkage matrix has been dropped."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "from_mlab_linkage",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.cluster.hierarchy._hierarchy_impl:from_mlab_linkage"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "transform from Matlab to SciPy format."
            }
          ]
        }
      ],
      "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": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "for a description of what a linkage matrix is."
            }
          ]
        }
      ],
      "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
        }
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "to_mlab_linkage"
  },
  "references": null,
  "qa": "scipy.cluster.hierarchy._hierarchy_impl:to_mlab_linkage",
  "arbitrary": [],
  "local_refs": [
    "Z",
    "to_mlab_linkage"
  ]
}