- Sorting = putting elements in an ordered sequence (like numeric, alphabetic, ascending, descending, etc.)
- sort() -> function of NumPy ndarray object, that sorts a specified array
ab = np.array([5, 3, 4, 0, 2, 1])
print(np.sort(ab))
Output:
[0 1 2 3 4 5]
NOTE: sort() returns a copy of the array, leaving the original array unchanged.
ac = np.array(['pear', 'banana', 'apple', 'mango'])
np.sort(ac)
Output
['apple', 'banana', 'mango', 'pear']
ad = np.array([True, False, True, True, False, False])
np.sort(ad)
Output:
[False False False True True True]
ae = np.array([[21, 10, 3], [8, -6, 4], [3, 0, -2]])
np.sort(ae)
Output:
[[3 10 21] [-6 4 8] [-2 0 3]]