{
  "__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": "indices",
              "annotation": "(m, n, ...) ndarray of ints",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Array of indices that sort the keys along the specified axis."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Perform an indirect stable sort using a sequence of keys."
            }
          ]
        }
      ],
      "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": "keys",
              "annotation": "(k, m, n, ...) array-like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "k",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " keys to be sorted. The "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "last"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " key (e.g, the last row if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "keys"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a 2D array) is the primary sort key. Each element of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "keys"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " along the zeroth axis must be an array-like object of the same shape."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis to be indirectly sorted. By default, sort over the last axis of each sequence. Separate slices along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " sorted over independently; see last example."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Given multiple sorting keys, lexsort returns an array of integer indices that describes the sort order by multiple keys. The last key in the sequence is used for the primary sort order, ties are broken by the second-to-last key, and so on."
            }
          ]
        }
      ],
      "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": null,
  "item_line": null,
  "item_type": "_ArrayFunctionDispatcher",
  "aliases": [
    "numpy.lexsort"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Sort names: first by surname, then by name.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nsurnames =    ('Hertz',    'Galilei', 'Hertz')\nfirst_names = ('Heinrich', 'Galileo', 'Gustav')\nind = np.lexsort((first_names, surnames))\nind\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "[surnames[i] + \", \" + first_names[i] for i in ind]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSort according to two numerical keys, first by elements\nof ``a``, then breaking ties according to elements of ``b``:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "a = [1, 5, 1, 4, 3, 4, 4]  # First sequence\nb = [9, 4, 0, 4, 0, 2, 1]  # Second sequence\nind = np.lexsort((b, a))  # Sort by `a`, then by `b`\nind\n[(a[i], b[i]) for i in ind]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCompare against `argsort`, which would sort each key independently.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.argsort((b, a), kind='stable')\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nTo sort lexicographically with `argsort`, we would need to provide a\nstructured array.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.array([(ai, bi) for ai, bi in zip(a, b)],\n             dtype = np.dtype([('x', int), ('y', int)]))\nnp.argsort(x)  # or np.argsort(x, order=('x', 'y'))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe zeroth axis of `keys` always corresponds with the sequence of keys,\nso 2D arrays are treated just like other sequences of keys.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "arr = np.asarray([b, a])\nind2 = np.lexsort(arr)\nnp.testing.assert_equal(ind2, ind)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAccordingly, the `axis` parameter refers to an axis of *each* key, not of\nthe `keys` argument itself. For instance, the array ``arr`` is treated as\na sequence of two 1-D keys, so specifying ``axis=0`` is equivalent to\nusing the default axis, ``axis=-1``.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.testing.assert_equal(np.lexsort(arr, axis=0),\n                        np.lexsort(arr, axis=-1))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFor higher-dimensional arrays, the axis parameter begins to matter. The\nresulting array has the same shape as each key, and the values are what\nwe would expect if `lexsort` were performed on corresponding slices\nof the keys independently. For instance,\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = [[1, 2, 3, 4],\n     [4, 3, 2, 1],\n     [2, 1, 4, 3]]\ny = [[2, 2, 1, 1],\n     [1, 2, 1, 2],\n     [1, 1, 2, 1]]\nnp.lexsort((x, y), axis=1)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nEach row of the result is what we would expect if we were to perform\n`lexsort` on the corresponding row of the keys:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "for i in range(3):\n    print(np.lexsort((x[i], y[i])))\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "argsort",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "argsort"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Indirect sort."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "ndarray.sort",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "ndarray.sort"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In-place sort."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "sort",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "numpy:lexsort"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Return a sorted copy of an array."
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "keys",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "-1"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "lexsort"
  },
  "references": null,
  "qa": "numpy:lexsort",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "indices",
    "keys"
  ]
}