Sort by First Column
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
1 <= rows <= 101 <= columns <= 5
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Subtract Row MinimumMedium
- Unit VectorsMedium
- Best Square BlockHard
- Crossing AboveHard
- Current StreakHard
- Finished SudokuHard
- First Time at a LevelHard
- Higher Than Its NeighborsHard