0

I have the following matrix

 a=np.array([[1,-2],[2,-3]])

and i want to obtain this one

[[2,-3],[1,-2]]

meaning i have sorted the matrix with respect to the 2nd column.

I have tried the following code that don't work

  a=np.array([[1,-2],[2,-3]])
  a.sort(axis=1)
  print(a)

which give me

 [[-2,1],[-3,2]]

Thank you for your answers

  • 7
    Possible duplicate of [Sorting arrays in NumPy by column](https://stackoverflow.com/questions/2828059/sorting-arrays-in-numpy-by-column) – Lev Zakharov Aug 08 '18 at 14:17
  • 1
    duplicate question, check [sorting-arrays-in-numpy-by-column](https://stackoverflow.com/questions/2828059/sorting-arrays-in-numpy-by-column) a simple solusion is a[a[:,1].argsort()] – A_sh Aug 08 '18 at 14:25

0 Answers0