Skip to main content

NumPy: Sorting Arrays Using argsort()

It is used to return the indices that would sort an array.
It performs an indirect sorting along the specified axis and kind keyword. It returns an array of indices of the same shape as that index data along the given axis in sorted order.

Syntax:

numpy.argsort(a, axis=- 1, kind=None, order=None)

Example:

import numpy as np
marks=np.array([80,50,20,70,60,10])
b=np.argsort(marks,axis=0)
#It is used to returns the indices that would sort an array.
print(b)

Output: [5 2 1 4 3 0]

Submitted by devanshi.srivastava on September 7, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.