Sorting Along an Axis
sort works along an axis. partition finds the k smallest quickly.
Example
a = np.array([[3, 1, 2], [9, 7, 8]])
print(np.sort(a, axis=1))
print(np.sort(a, axis=0))
print(np.sort(a, axis=None)[::-1])Result
[[1 2 3] [7 8 9]] [[3 1 2] [9 7 8]] [9 8 7 3 2 1]
Exercise
Along rows.
np.sort(a, axis=)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.