Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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?
ASorts each row independently
BSorts each column independently
CSorts the entire array as a flat list
DDoes not sort anything
✗ 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?
Aaxis=0
Baxis=None
Caxis=-1
Daxis=1
✗ 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?
Aaxis=0
Baxis=1
Caxis=-1 (last axis)
Daxis=None (flattened)
✗ 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?
Aarray.sort()
Bnp.argsort()
Cnp.sorted()
Dnp.sort()
✗ Incorrect
array.sort() sorts the array in-place along the specified axis.
Sorting a 3D array along axis=2 means sorting along which dimension?
AThe third dimension
BThe second dimension
CThe first dimension
DThe flattened array
✗ 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.
Practice
(1/5)
1. What does the axis parameter control in numpy.sort?
easy
A. It decides whether to sort rows or columns in an array.
B. It sets the sorting algorithm type.
C. It changes the data type of the array before sorting.
D. It specifies the order of sorting (ascending or descending).
Solution
Step 1: Understand the role of axis in sorting
The axis parameter tells numpy which direction to sort: 0 means sort each column, 1 means sort each row.
Step 2: Differentiate from other parameters
Sorting algorithm type and order are controlled by other parameters, not axis.
Final Answer:
It decides whether to sort rows or columns in an array. -> Option A