9951 explained code solutions for 126 technologies


python-numpyHow to sort Numpy array descending


import numpy as np
a = np.array([3, 1, 4, 2, 5])

sorted = -np.sort(-a)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

-np.sort(-a)

will sort negative values of a given a array and then change values signs (magic to sort in descending order)

sorted

will contain sorted array