0
0
NumPydata~5 mins

Sorting along axes in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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
If you want to sort each row of a 2D array, which axis should you use?
Aaxis=0
Baxis=None
Caxis=-1
Daxis=1
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)
Which function would you use to sort a NumPy array in-place along an axis?
Aarray.sort()
Bnp.argsort()
Cnp.sorted()
Dnp.sort()
Sorting a 3D array along axis=2 means sorting along which dimension?
AThe third dimension
BThe second dimension
CThe first dimension
DThe flattened 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.