temp[::-1].sort() sorts the array in place, whereas np.sort(temp)[::-1] creates a new array.

In [25]: temp = np.random.randint(1,10, 10)

In [26]: temp
Out[26]: array([5, 2, 7, 4, 4, 2, 8, 6, 4, 4])

In [27]: id(temp)
Out[27]: 139962713524944

In [28]: temp[::-1].sort()

In [29]: temp
Out[29]: array([8, 7, 6, 5, 4, 4, 4, 4, 2, 2])

In [30]: id(temp)
Out[30]: 139962713524944
Answer from Padraic Cunningham on Stack Overflow
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third-party โ€บ numpy โ€บ sort
Python Numpy sort() - Sort Elements | Vultr Docs
December 31, 2024 - In this article, you will learn how to proficiently use the sort() function to manage array data. You'll explore how to apply it to various array structures and discover tips for optimal sorting strategies. Import the NumPy library.
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ sort numpy array in descending order
Sort Numpy Array in Descending Order - Data Science Parichay
July 2, 2022 - Sort the array in ascending order using the numpy.sort() function. Reverse the array using slicing (ar[::-1]) to get the array with elements in descending order.
๐ŸŒ
Medium
medium.com โ€บ @whyamit404 โ€บ sorting-numpy-arrays-by-column-using-numpy-sort-c45a44660dcc
Sorting NumPy Arrays by Column Using numpy.sort() | by whyamit404 | Medium
February 26, 2025 - [::-1] reverses the order of the sorted array, giving you a descending sort. I hope these answers help clear up any confusion you had. The great thing about sorting in NumPy is the flexibility it offers.
๐ŸŒ
Wellsr
wellsr.com โ€บ python โ€บ sorting-numpy-arrays-in-python
How to Sort NumPy Arrays in Python (with Examples) - wellsr.com
April 29, 2022 - One way to sort a NumPy array in descending order is to first sort the array in ascending order using the sort() function and then you can apply any array reversal technique to get the final array where the items are sorted in descending order.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ numpy โ€บ how-to-use-numpy-argsort-in-descending-order-in-python
How to use numpy.argsort in Descending order in Python - GeeksforGeeks
July 23, 2025 - In this example, we are negating the NumPy Array to sort it in descending order using numy.argsort(). Here, we will use argsort() to get the indices that would sort the original array in ascending order.
Find elsewhere
๐ŸŒ
IncludeHelp
includehelp.com โ€บ python โ€บ is-it-possible-to-use-numpy-argsort-in-descending-order.aspx
Python - Is it possible to use numpy.argsort() in descending order?
May 25, 2023 - # Import numpy import numpy as np # Creating an empty numpy array arr = np.array([1, 8, 6, 9, 4]) # Display original array print("Orignal array:\n",arr,"\n") # 5 Sorted indices in ascending order res_asc = arr.argsort()[:5] # Display sorted indices in ascending order print("Sorted indices in ascending order:\n",res_asc,"\n") # 5 sorted indices i descending order res_asc = (-arr).argsort()[:5] # Display sorted indices in descending order print("Sorted indices in descending order:\n",res_asc)
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ problem with sorting in descending order
r/learnpython on Reddit: Problem with sorting in descending order
October 6, 2023 -

Hi, I am trying to sort in descending order in jupyter notebook

I tried from:StackExchange

import numpy as np #import numpy
games = np.array(['FIFA 2020','Red Dead Redemption','Fallout','GTA','NBA 2018','Need For Speed'])
print(games)
print("1",np.sort(games))
games = np.sort(games)
np.sort(games, order='descending')

But I am getting the error

ValueError: Cannot specify order when the array has no fields. 

Somebody, please guide me.

Zulfi.

Top answer
1 of 2
3
I think you are misunderstanding the order parameter. It doesn't do what you seem to think it does: >>> import numpy as np >>> help(np.sort) Help on _ArrayFunctionDispatcher in module numpy: sort(a, axis=-1, kind=None, order=None) Return a sorted copy of an array. Parameters ---------- ... order : str or list of str, optional When `a` is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties. So order requires your array to have pre-defined "fields", whose members you pass in as order in the order you'd like them sorted according to. "descending" is obviously not a "field" of your array, hence it's not working. Note that despite ascending-order sorting seeming to work in your sample code, if you specify the order as such, you get the same error: >>> import numpy as np >>> games = np.array(['FIFA 2020','Red Dead Redemption','Fallout','GTA','NBA 2018','Need For Speed']) >>> np.sort(games, order='ascending') Traceback (most recent call last): ... ValueError: Cannot specify order when the array has no fields. Looking into this, it seems numpy.sort actually doesn't support descending order. So to achieve the same, just sort in ascending order, then slice in reverse: >>> np.sort(games)[::-1] array(['Red Dead Redemption', 'Need For Speed', 'NBA 2018', 'GTA', 'Fallout', 'FIFA 2020'], dtype='
2 of 2
3
Do you need numpy here? Seems overkill. games = ['FIFA 2020','Red Dead Redemption','Fallout','GTA','NBA 2018','Need For Speed'] sorted(games, reverse=True)
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-sort-lists-and-reverse-arrays
Python Sorted List โ€“ And How to Sort or Reverse an Array in Python
February 24, 2023 - In this article, we will learn how to reverse an array using slicing and the reverse() method. We will also talk about how to sort lists in Python using the sort() method, sorted() function, and the heapq module.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python:numpy โ€บ ndarray โ€บ .sort()
Python:NumPy | ndarray | .sort() | Codecademy
October 30, 2025 - In the following codebyte example, a NumPy array nf is created with integers, sorted in ascending order using NumPyโ€™s .sort() method, and then reversed to display the values in descending order:
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ sorting-and-unary-operations-in-num-py
Sorting and Unary Operations in NumPy | Codecademy
To sort in NumPy, we can use the numpy.sort() function. By default, it sorts an array of numbers in ascending order. While direct sorting in descending order isnโ€™t available through this function, it can be achieved by sorting in ascending order and then reversing the result.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ numpy-sort
NumPy Sort: How to Sort a NumPy Array
This lesson covers NumPy sort, NumPy Argsort, and additional functions you can use to sort a NumPy array.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ sort
NumPy sort()
The sort() method returns a sorted array. import numpy as np array = np.array([10.20, 2.10, 9.9, -1.4])
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ sorting-arrays
NumPy Sorting Arrays
NumPy's array sorting capabilities are used to reorder elements within an array to facilitate data organization or analysis.