np.sort descending
array = np.array([7, 5, 3, 2, 6, 1, 4])
# Sort in ascending order
sorted_array = np.sort(array)
# [1, 2, 3, 4, 5, 6, 7]
# Reverse the sorted array
reverse_array = sorted_array[::-1]
# [7, 6, 5, 4, 3, 2, 1]
np.sort descending
array = np.array([7, 5, 3, 2, 6, 1, 4])
# Sort in ascending order
sorted_array = np.sort(array)
# [1, 2, 3, 4, 5, 6, 7]
# Reverse the sorted array
reverse_array = sorted_array[::-1]
# [7, 6, 5, 4, 3, 2, 1]
numpy sort
>>> a = np.array([[1,4],[3,1]])
>>> np.sort(a) # sort along the last axis
array([[1, 4],
[1, 3]])
>>> np.sort(a, axis=None) # sort the flattened array
array([1, 1, 3, 4])
>>> np.sort(a, axis=0) # sort along the first axis
array([[1, 1],
[3, 4]])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us