I am just wondering how to sort a NumPy array in descending order using NumPy sort() function efficiently. I checked the NumPy official documentation and StackOverflow question but I couldn`t able to find how to sort a NumPy array in descending order using the NumPy sort().
For instance:
import numpy as np
arr=np.array([1,5,8,4,5])
arr.sort()
print(arr)
Output:
[1,4,5,5,8]
I want to sort it by descending order, I understand after sorting the array in ascending order, I can reverse it like below.
arr.sort()[::-1]
But it creates a new array, Is it possible to sort descending without approaching this method?
arr[::-1].sort()[::-1]creates a view, not a copy.