Sort Rows by a Column

mediumnumpy_indexing

Implement sort_by_column(X, k).

Given a 2D array X and a column index k, return X with its rows reordered so that column k is ascending. Use argsort + fancy indexing — no for/while loops.

Constraints
  • no scipy, sklearn
  • no for/while loops

Your solution

Edit sort_by_column and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

argsort the chosen column to get a row order, then index the rows with it.