In this article we will learn how to sort a NumPy Array in descending order.
Table Of Contents
 Sort NumPy Array in decreasing order using sort()
 Sort 2D NumPy Array in decreasing Order Rowwise
 Sort 2D NumPy Array in decreasing Order Columnwise
 Sort NumPy Array in decreasing order using sort() and flip()
Given a NumPy Array we need to to sort the array in descending order i.e the elements needed to be rearranged in decreasing order. For example,
If input array is like this,
[1,2,3,4,4,5,6,7]
Then after sorting in decreasing order, the output array must be like this,
[7,6,5,4,4,3,2,1]
There are multiple ways to sort a NumPy Array in descending order. Lets discuss all the methods one by one with proper approach and a working code example
Sort NumPy Array in decreasing order using sort()
The sort() method is a builtin method in numpy that takes an array as input and return a sorted copy of an array. It
arranges all the elements in increasing order.
In order to sort a NumPy Array in descending order, we will pass the given array to the sort() method and it will return the sorted array in ascending order. Then we will reverse the array using slicing. This method will work for 1d numpy arrays.
Syntax of numpy.sort() :
numpy.sort(array,axis)
Parameters:
 array = The array to be passed to the function.
 axis = Axis 0 represents rows and axis 1 represents columns, if no axis is provided then the input array will be flattened i.e treated as a 1d array.
Return:
 Return a sorted copy of an array.
Approach :
 Import numpy library and create a numpy array
 Pass the array to the sort() method
 The function will return the sorted array in ascending order
 Now reverse the returned array using slicing i.e array[::1]
Print the resultant array.
Source code
import numpy as np # Creating numpy array arr = np.array([1,2,3,4,4,5,6,7] ) # Sort NumPy Array in decreasing order arr = np.sort(arr)[::1] print(arr)
OUTPUT:
[7 6 5 4 4 3 2 1]
Sort 2D NumPy Array in decreasing Order Rowwise
The sort() method is a builtin method in numpy that takes an array as input and Return a sorted copy of an array. i.e by arranging all the elements in increasing order. In order to sort a NumPy Array in descending order, First we will multiply all the elements in the array with 1 and we will pass the resultant array to the sort() method and it returns the sorted array in increased order. The large negative numbers will have smallest value so they will come first in the sorted array, now we will again multiply the elements in the array with 1. The resultant array will be decreasingly sorted array. The method can be used for both 1d and nd arrays.
You can better understand this method by the following example.
EXAMPLE: Input Array : [9,4,5,2,7,3,8] array after multiply with 1 : [9,4,5,2,7,3,8] Sorting the above array : [9,8,7,5,4,3,2] Again multiply with 1 : [9,8,7,5,4,3,2] and array is now sorted in decreasing order.
Syntax:
numpy.sort(array,axis)
Parameters:
 array = The array to be passed to the function.
 axis = Axis 0 represents rows and axis 1 represents columns, if no axis is provided then the input array will be flattened i.e treated as a 1d array.
Return:
 Return a sorted copy of an array.
Approach :
 import numpy library and create a numpy array
 Now multiply the all the elements of array with 1
 Pass the array to the SORT() method
 The function will return the sorted array in ascending order
 Now multiply the all the elements of returned array with 1
 print the resultant array.
Source code
import numpy as np # Creating numpy array arr = np.array([[3, 2, 4], [5, 0, 1]]) # Sort 2D NumPy Array in decreasing order rowwise arr = np.sort(arr) print(arr)
OUTPUT:
[[4 3 2] [5 1 0]]
Sort 2D NumPy Array in decreasing Order Columnwise
This method is exact same as above so i am saving ink in my pen. To sort the array decreasingly in Columnwise we just need to keep the axis parameter of the sort method to zero i.e axis=0.
Approach :
 import numpy library and create a numpy array
 Now multiply the all the elements of array with 1
 Pass the array to the SORT() method with axis=0
 The function will return the sorted array in ascending order
 Now multiply the all the elements of returned array with 1
 print the resultant array.
Sort 2D NumPy Array in decreasing Order column wise
import numpy as np # Creating numpy array arr = np.array([[3, 2, 4], [5, 0, 1], [1, 9, 7]]) # Sort 2D NumPy Array in decreasing order rowwise arr = np.sort(arr, axis=0) print(arr)
Output:
[[5 9 7] [3 2 4] [1 0 1]]
Sort NumPy Array in decreasing order using sort() and flip()
The sort() method is a builtin method in numpy that takes an array as input and Return a sorted copy of an array. i.e by arranging all the elements in increasing order. In order to sort a NumPy Array in descending order, we will pass the given array to the sort() method
and it returns the sorted array in increased order. Now we will reverse the array using flip(). The flip() method is a builtin method in numpy that takes an array as input and Return the array by Reversing the order of elements in an array along the given axis. The shape of the array is preserved, but the elements are reordered.
Syntax of numpy.flip():
numpy.flip(array,axis) Parameters: array = The array to be passed to the function. axis = The default, axis=None Return: Returns an array
Approach :
 Import numpy library and create a numpy array
 Pass the array to the SORT() method to sort the array
 The function will return the sorted array in ascending order
 Now reverse the returned array using flip() method
print the resultant array.
Source code
import numpy as np # Creating numpy array arr = np.array([1,2,3,4,4,5,6,7] ) # Sort NumPy Array in decreasing order arr = np.flip( np.sort(arr) ) print(arr)
OUTPUT:
[7 6 5 4 4 3 2 1]
Summary
Great! you made it, We have discussed All possible methods for sorting the numpy array in descending order. Happy learning.
Pandas Tutorials Learn Data Analysis with Python

Pandas Tutorial Part #1  Introduction to Data Analysis with Python

Pandas Tutorial Part #2  Basics of Pandas Series

Pandas Tutorial Part #3  Get & Set Series values

Pandas Tutorial Part #4  Attributes & methods of Pandas Series

Pandas Tutorial Part #5  Add or Remove Pandas Series elements

Pandas Tutorial Part #6  Introduction to DataFrame

Pandas Tutorial Part #7  DataFrame.loc[]  Select Rows / Columns by Indexing

Pandas Tutorial Part #8  DataFrame.iloc[]  Select Rows / Columns by Label Names

Pandas Tutorial Part #9  Filter DataFrame Rows

Pandas Tutorial Part #10  Add/Remove DataFrame Rows & Columns

Pandas Tutorial Part #11  DataFrame attributes & methods

Pandas Tutorial Part #12  Handling Missing Data or NaN values

Pandas Tutorial Part #13  Iterate over Rows & Columns of DataFrame

Pandas Tutorial Part #14  Sorting DataFrame by Rows or Columns

Pandas Tutorial Part #15  Merging or Concatenating DataFrames

Pandas Tutorial Part #16  DataFrame GroupBy explained with examples
Are you looking to make a career in Data Science with Python?
Data Science is the future, and the future is here now. Data Scientists are now the most soughtafter professionals today. To become a good Data Scientist or to make a career switch in Data Science one must possess the right skill set. We have curated a list of Best Professional Certificate in Data Science with Python. These courses will teach you the programming tools for Data Science like Pandas, NumPy, Matplotlib, Seaborn and how to use these libraries to implement Machine learning models.
Checkout the Detailed Review of Best Professional Certificate in Data Science with Python.
Remember, Data Science requires a lot of patience, persistence, and practice. So, start learning today.