Yes, there's the x = numpy.argsort(a) function or x = numpy.ndarray.argsort(a) method. It does exactly what you're asking for. You can also call argsort as a method on an ndarray object like so: a.argsort().

Here's a link to the documentation: http://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html#numpy.argsort

Answer from Phillip Cloud on Stack Overflow
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.argsort.html
numpy.argsort โ€” NumPy v2.2 Manual
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 a that index data along the given axis in sorted order.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.argsort.html
numpy.argsort โ€” NumPy v2.6.dev0 Manual
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 a that index data along the given axis in sorted order.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-argsort-in-python
numpy.argsort() in Python - GeeksforGeeks
July 11, 2025 - numpy.argsort() is a function in NumPy that returns the indices that would sort an array. In other words, it gives you the indices that you would use to reorder the elements in an array to be in sorted order.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third party โ€บ numpy โ€บ argsort()
Python Numpy argsort() - Sort Array Indices
November 11, 2024 - This code snippet sorts the data array and returns the indices that sort the array.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ argsort
NumPy argsort()
The argsort() method in NumPy sorts the array elements in ascending order and returns indices of the sorted elements. The argsort() method in NumPy sorts the array elements in ascending order and returns indices of the sorted elements.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.searchsorted.html
numpy.searchsorted โ€” NumPy v2.2 Manual
Find the indices into a sorted array a such that, if the corresponding elements in v were inserted before the indices, the order of a would be preserved.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ numpy-sort
NumPy Sort: How to Sort a NumPy Array
Use the NumPy argsort command - np.argsort() - to return indices that would sort the array.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-the-indices-of-the-sorted-array-using-numpy-in-python
How to Get the Indices of the Sorted Array using NumPy in Python - GeeksforGeeks
September 27, 2025 - The numpy.argsort() function is used to get indices that would sort a NumPy array. Instead of returning sorted array, it returns positions of the elements in order that sorts the array.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.searchsorted.html
numpy.searchsorted โ€” NumPy v2.5 Manual
Find the indices into a sorted array a such that, if the corresponding elements in v were inserted before the indices, the order of a would be preserved.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ sorting-and-unary-operations-in-num-py
Sorting and Unary Operations in NumPy | Codecademy
... This method is efficient for ... copies of the data. The numpy.argsort() function returns the indices of the elements in an array that would sort the array in ascending order....
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.searchsorted.html
numpy.searchsorted โ€” NumPy v2.6.dev0 Manual
Find the indices into a sorted array a such that, if the corresponding elements in v were inserted before the indices, the order of a would be preserved.
๐ŸŒ
JAX Documentation
docs.jax.dev โ€บ en โ€บ latest โ€บ _autosummary โ€บ jax.numpy.argsort.html
jax.numpy.argsort โ€” JAX documentation
jax.numpy.argsort(a, axis=-1, *, kind=None, order=None, stable=True, descending=False, dtype=None)[source]# Return indices that sort an array.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 1.25 โ€บ reference โ€บ generated โ€บ numpy.argsort.html
numpy.argsort โ€” NumPy v1.25 Manual
Array of indices that sort a along the specified axis. If a is one-dimensional, a[index_array] yields a sorted a.