Premium problem24. Sort Rows by nth Column

Medium Locked

Sort the rows of matrix Z by the values in its n-th column. Return the sorted matrix.

Input

Z =
tensor([[3, 7, 1],
        [1, 2, 9],
        [2, 5, 5]])
n = 1

Output

tensor([[1, 2, 9],
        [2, 5, 5],
        [3, 7, 1]])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)