What is the role of the axis parameter in NumPy's sorting functions?

Quick Overview

Asks what the axis parameter controls in NumPy sort, argsort and partition, and how the result differs for axis 0, axis -1 and None. It tests whether you understand sorting independent slices and can avoid scrambling the rows of a 2-D array.

What is the role of the axis parameter in NumPy's sorting functions?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the role of the `axis` parameter in NumPy's sorting functions? ```hint Picture the slices Fix every index except one and look at the 1-D slice that remains. Ask what happens to the other values in the same row when one column is sorted. ``` ### What a Strong Answer Covers - What sorting along an axis means in terms of independent 1-D slices - The default value, and what `axis=0`, `axis=-1` and `axis=None` do on a 2-D array - What happens to the shape of the result - Why sorting along axis 0 breaks up rows, and how to reorder whole rows by one column - Which related functions take the same parameter ### Follow-up Questions - How would you sort the rows of a 2-D array by the values in its second column? - How do you use `np.argsort` with `axis` to reorder a second array the same way? - How would you sort each row in descending order? - When does passing `kind="stable"` matter?

Overview: Asks what the axis parameter controls in NumPy sort, argsort and partition, and how the result differs for axis 0, axis -1 and None. It tests whether you understand sorting independent slices and can avoid scrambling the rows of a 2-D array.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the role of the axis parameter in NumPy's sorting functions?

What a Strong Answer Covers Guidance

  • What sorting along an axis means in terms of independent 1-D slices
  • The default value, and what axis=0 , axis=-1 and axis=None do on a 2-D array
  • What happens to the shape of the result
  • Why sorting along axis 0 breaks up rows, and how to reorder whole rows by one column
  • Which related functions take the same parameter

Follow-up Questions Guidance

  • How would you sort the rows of a 2-D array by the values in its second column?
  • How do you use np.argsort with axis to reorder a second array the same way?
  • How would you sort each row in descending order?
  • When does passing kind="stable" matter?