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
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.sort.html
numpy.sort — NumPy v2.5 Manual
Sort order. If True, the returned array will be sorted in descending order. If False or None, the returned array will be sorted in ascending order. Values that are NaN are sorted to the end for both orders.
Discussions

Problem with sorting in descending order
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=' More on reddit.com
🌐 r/learnpython
3
1
October 6, 2023
python - How to sort in descending order with numpy? - Stack Overflow
There's no reverse option in NumPy's sort or argsort functions because reversing an array is so efficient (it just changes the strides, no data need be copied). A solution via sorting -A would work, but that creates two new arrays instead of one. More on stackoverflow.com
🌐 stackoverflow.com
Can we sort Numpy arrays in reverse order?
Question In the context of this exercise, can we sort Numpy arrays in reverse order? Answer In Numpy, the np.sort() function does not allow us to sort an array in descending order. Instead, we can reverse an array utilizing list slicing in Python, after it has been sorted in ascending order. More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
9
August 31, 2018
Sorting 2d Array
Posted by u/PhantomWizard2099 - 2 votes and 14 comments More on reddit.com
🌐 r/learnpython
14
2
June 28, 2023
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_sort.asp
NumPy Sorting Arrays
Ordered sequence is any sequence that has an order corresponding to elements, like numeric or alphabetical, ascending or descending. The NumPy ndarray object has a function called sort(), that will sort a specified array.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.sort.html
numpy.sort — NumPy v2.6.dev0 Manual
For numerical sorts, NaT and NaN always sort to the end of the array for both ascending and descending sort 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.
🌐
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)
🌐
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 - Using [::-1] reverses those indices to achieve descending order. ... As you can see, the array is now sorted based on the first column, but in descending order.
Find elsewhere
🌐
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 - To sort a Numpy array in descending order, first, sort it in ascending order and then reverse the array using slicing.
🌐
Like Geeks
likegeeks.com › home › python › numpy › sorting numpy arrays: a comprehensive guide
Sorting NumPy Arrays: A Comprehensive Guide
To sort a NumPy array in descending order (from largest to smallest), we will still use np.sort(), but we will reverse the order of the sorted array.
🌐
Codecademy
codecademy.com › article › sorting-and-unary-operations-in-num-py
Sorting and Unary Operations in NumPy | Codecademy
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.
🌐
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.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.argsort.html
numpy.argsort — NumPy v2.5 Manual
Sort order. If True, the returned array will be sorted in descending order. If False or None, the returned array will be sorted in ascending order. Values that are NaN are sorted to the end for both orders.
🌐
Statology
statology.org › home › how to sort a numpy array by column (with examples)
How to Sort a NumPy Array by Column (With Examples)
December 6, 2021 - Notice that the rows are now sorted in descending order (largest to smallest) based on the values in the second column. The following tutorials explain how to perform other common operations in Python: How to Find Index of Value in NumPy Array How to Get Specific Column from NumPy Array How to Add a Column to a NumPy Array
🌐
Codegive
codegive.com › blog › numpy_sort_in_descending_order.php
Numpy sort in descending order
NumPy provides powerful tools for ... np.sort() (which returns a new sorted array) and then reverse the order of this newly sorted array using array slicing [::-1]....
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › sort
Python Numpy sort() - Sort Elements | Vultr Docs
December 31, 2024 - Here, array is first sorted in ascending order and then reversed to get [9, 6, 5, 4, 3, 2, 1, 1] in descending order. Create a two-dimensional array. Sort along a specified axis. ... array_2d = np.array([[12, 15], [10, 1]]) sorted_array_2d = np.sort(array_2d, axis=0) print(sorted_array_2d) Explain Code · The code sorts array_2d along each column (axis=0), reshuffling the rows to maintain order along columns, resulting in [[10, 1], [12, 15]]. Understand that NumPy supports various sorting algorithms such as 'quicksort', 'mergesort', and 'heapsort'.
🌐
Sharp Sight
sharpsight.ai › blog › numpy-sort
A quick guide to NumPy sort - Sharp Sight
February 6, 2024 - As you can see, the code -np.sort(-array_2d, axis = 0) produces an output array where the columns have been sorted in descending order, from the top of the column to the bottom.
🌐
DataCamp
datacamp.com › doc › numpy › sorting-arrays
NumPy Sorting Arrays
numpy.sort(a, axis=-1, kind='quicksort', order=None) In this syntax, a is the array to be sorted, axis specifies the axis along which to sort, kind determines the sorting algorithm, and order is used when sorting structured arrays.
🌐
Codegive
codegive.com › blog › numpy_sort_array_descending.php
Numpy sort array descending
NumPy, the fundamental package for numerical computation in Python, provides powerful and efficient tools for array manipulation, including sorting. While NumPy's primary sorting functions (np.sort and ndarray.sort) by default sort in ascending order, achieving a descending sort is straightforward using a combination of these functions and array slicing.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
Can we sort Numpy arrays in reverse order? - Python FAQ - Codecademy Forums
August 31, 2018 - Answer In Numpy, the np.sort() function does not allow us to sort an array in descending order. Instead, we can reverse an array utilizing list slicing in Python, after it has been sorted in ascending order.