{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "v = squareform(X)"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Given a square n-by-n symmetric distance matrix "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",    "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "v = squareform(X)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " returns an "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n * (n-1) / 2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    (i.e. binomial coefficient n choose 2) sized vector "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "v",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    where "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "v[{n \\choose 2} - {n-i \\choose 2} + (j-i-1)]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    is the distance between distinct points "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "i"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "j"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".    If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is non-square or asymmetric, an error is raised."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X = squareform(v)"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Given an "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n * (n-1) / 2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " sized vector "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "v"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    for some integer "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n >= 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " encoding distances as described,    "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X = squareform(v)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " returns an n-by-n distance matrix "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".    The "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X[i, j]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X[j, i]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " values are set to    "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "v[{n \\choose 2} - {n-i \\choose 2} + (j-i-1)]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    and all diagonal elements are zero."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In SciPy 0.19.0, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "squareform"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " stopped casting all input types to float64, and started returning arrays of the same dtype as the input."
            }
          ]
        }
      ],
      "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": "Y",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If a condensed distance matrix is passed, a redundant one is returned, or if a redundant one is passed, a condensed distance matrix is returned."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Convert a vector-form distance vector to a square-form distance matrix, and vice-versa."
            }
          ]
        }
      ],
      "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": "X",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Either a condensed or redundant distance matrix."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "force",
              "annotation": "str, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "As with MATLAB(TM), if force is equal to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'tovector'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "'tomatrix'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", the input will be treated as a distance matrix or distance vector respectively."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "checks",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If set to False, no checks will be made for matrix symmetry nor zero diagonals. This is useful if it is known that "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "X - X.T1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is small and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "diag(X)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is close to zero. These values are ignored any way so they do not disrupt the squareform transformation."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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": "/scipy/spatial/distance.py",
  "item_line": 2154,
  "item_type": "function",
  "aliases": [
    "scipy.cluster._optimal_leaf_ordering.squareform"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.spatial.distance import pdist, squareform\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n``x`` is an array of five points in three-dimensional space.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.array([[2, 0, 2], [2, 2, 3], [-2, 4, 5], [0, 1, 9], [2, 2, 4]])\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n``pdist(x)`` computes the Euclidean distances between each pair of\npoints in ``x``.  The distances are returned in a one-dimensional\narray with length ``5*(5 - 1)/2 = 10``.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "distvec = pdist(x)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "distvec\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n``squareform(distvec)`` returns the 5x5 distance matrix.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "m = squareform(distvec)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "m\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWhen given a square distance matrix ``m``, ``squareform(m)`` returns\nthe one-dimensional condensed distance vector associated with the\nmatrix.  In this case, we recover ``distvec``.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "squareform(m)\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "X",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "force",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "no"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "checks",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "True"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "squareform"
  },
  "references": null,
  "qa": "scipy.spatial.distance:squareform",
  "arbitrary": [],
  "local_refs": [
    "X",
    "Y",
    "checks",
    "force"
  ]
}