FunctionRacerProblemsRace

Sort by First Column

MediumNumPyPython

Return a new 2-D array with the rows of table reordered so the values in column 0 go from smallest to largest. Each row stays intact. Rows with equal column-0 values keep their original relative order. Hint: np.argsort with kind="stable", then index the rows.

Example 1

table [[3,7],[1,8],[2,9]]
returns [[1,8],[2,9],[3,7]]

The column 0 values 1, 2, 3 give rows [1, 8], [2, 9], [3, 7].

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems