Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
numpy
method
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)
Implementing the char.chararray.argsort() method

RELATED TAGS

python
numpy
method
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring