What is the numpy.char.chararray.argsort() method in Python?

Overview

The char.chararray.argsort() method in Python returns the indices that sort the input array. In other words, the char.chararray.argsort() method returns an array of indices along a given axis with the same shape as the input array in sorted order.

Syntax

char.chararray.argsort(axis=- 1, kind=None, order=None)
Implementing the char.chararray.argsort() method

Parameter value

The char.chararray.argsort() method takes the following parameter values:

  • axis: This is the axis that is to be sorted. The default value is given as -1, which specifies the last used axis. The None value is used for a flattened array. This is optional.
  • kind: This specifies the algorithm to be used for sorting. It takes the following values: quicksort, mergesort, heapsort, and stable. It takes quicksort as its default value. This is optional.
  • order: This specifies the order in which to compare the fields.

Example

import numpy as np
# creating an input array
x = np.array([[ 4, 6, 2], [ 5, 1, 3]])
# implementing the char.chararray.argsort() method
myarray = x.argsort(axis=1, kind='heapsort')
# printing the original array
print(x)
# printing the sorted array
print(myarray)

Free Resources