Recall & Review
beginner
What does sorting along an axis mean in a NumPy array?
Sorting along an axis means arranging the elements in order (usually ascending) along a specific dimension (row or column) of a NumPy array, without changing the other dimensions.
Click to reveal answer
beginner
How do you sort a 2D NumPy array along rows?
Use
np.sort(array, axis=1). This sorts each row independently, arranging elements in ascending order within each row.Click to reveal answer
intermediate
What is the default axis used by
np.sort() if none is specified?The default axis is -1, which means sorting is done along the last axis of the array.
Click to reveal answer
intermediate
How does sorting along axis=0 differ from axis=1 in a 2D array?
Sorting along axis=0 sorts each column independently (top to bottom), while axis=1 sorts each row independently (left to right).
Click to reveal answer
advanced
Can you sort a 3D NumPy array along a specific axis? How?
Yes. Use
np.sort(array, axis=n) where n is 0, 1, or 2. This sorts elements along that axis while keeping other axes intact.Click to reveal answer
What does
np.sort(arr, axis=0) do on a 2D array?✗ Incorrect
Sorting with axis=0 sorts elements down each column independently.
If you want to sort each row of a 2D array, which axis should you use?
✗ Incorrect
axis=1 sorts along rows, sorting elements within each row.
What is the default axis for
np.sort() if you don't specify it?✗ Incorrect
By default, np.sort sorts along the last axis (axis=-1).
Which function would you use to sort a NumPy array in-place along an axis?
✗ Incorrect
array.sort() sorts the array in-place along the specified axis.Sorting a 3D array along axis=2 means sorting along which dimension?
✗ Incorrect
Axis=2 refers to the third dimension in a 3D array.
Explain how sorting along different axes affects a 2D NumPy array.
Think about rows vs columns and how sorting changes their order.
You got /4 concepts.
Describe how to sort a 3D NumPy array along a specific axis and why this might be useful.
Consider how multi-dimensional data can be organized slice by slice.
You got /4 concepts.