How to get the indices of the sorted array using NumPy in Python? Last Updated : 21 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report We can get the indices of the sorted elements of a given array with the help of argsort() method. This function is used to perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as arr that would sort the array. Syntax: numpy.argsort(arr, axis=-1, kind=’quicksort’, order=None) Example 1: Python3 import numpy as np # Original array array = np.array([10, 52, 62, 16, 16, 54, 453]) print(array) # Indices of the sorted elements of a # given array indices = np.argsort(array) print(indices) Output: [ 10 52 62 16 16 54 453] [0 3 4 1 5 2 6] Example 2: Python3 import numpy as np # Original array array = np.array([1, 2, 3, 4, 5]) print(array) # Indices of the sorted elements of # a given array indices = np.argsort(array) print(indices) Output: [1 2 3 4 5] [0 1 2 3 4] Example 3: Python3 import numpy as np # input 2d array in_arr = np.array([[ 2, 0, 1], [ 5, 4, 3]]) print ("Input array :\n", in_arr) # output sorted array indices out_arr1 = np.argsort(in_arr, kind ='mergesort', axis = 0) print ("\nOutput sorted array indices along axis 0:\n", out_arr1) out_arr2 = np.argsort(in_arr, kind ='heapsort', axis = 1) print ("\nOutput sorted array indices along axis 1:\n", out_arr2) Output: Input array : [[2 0 1] [5 4 3]] Output sorted array indices along axis 0: [[0 0 0] [1 1 1]] Output sorted array indices along axis 1: [[1 2 0] [2 1 0]] Comment More infoAdvertise with us Next Article How to get the indices of the sorted array using NumPy in Python? J jyotikayadav2017 Follow Improve Article Tags : Python Python-numpy Python numpy-Sorting Searching Practice Tags : python Similar Reads How to get the number of dimensions of a matrix using NumPy in Python? In this article, we will discuss how to get the number of dimensions of a matrix using NumPy. It can be found using the ndim parameter of the ndarray() method. Syntax: no_of_dimensions = numpy.ndarray.ndim Approach: Create an n-dimensional matrix using the NumPy package.Use ndim attribute available 3 min read How to find the Index of value in Numpy Array ? In this article, we are going to find the index of the elements present in a Numpy array.Using where() Methodwhere() method is used to specify the index of a particular element specified in the condition.Syntax: numpy.where(condition[, x, y])Example 1: Get index positions of a given valueHere, we fi 5 min read How to get index of NumPy multidimensional array in reverse order? In this article, we will see how to get the index of the NumPy multidimensional array in reverse order. Approach First, we import the NumPy library and initialize the necessary parameters which include the matrix which we need to work upon and other required parameters.Now we are going to loop over 3 min read How to rearrange columns of a 2D NumPy array using given index positions? In this article, we will learn how to rearrange columns of a given numpy array using given index positions. Here the columns are rearranged with the given indexes. For this, we can simply store the columns values in lists and arrange these according to the given index list but this approach is very 2 min read How to get the n-largest values of an array using NumPy? Let's see the program for how to get the n-largest values of an array using NumPy library. For getting n-largest values from a NumPy array we have to first sort the NumPy array using numpy.argsort() function of NumPy then applying slicing concept with negative indexing. Syntax: numpy.argsort(arr, ax 2 min read Like