0

I have an numpy array arr with shape (1500,10) where each element is a digit from 0 to 9. I'd like to sort the array as each row's elements are concatenated to form a single number and then sort these numbers in ascending order.Let a simple array be like:

arr = ([[3,4,1,5,1,2,3,4,5,6],
       [1,2,3,5,6,2,9,2,1,2],
       [0,3,1,4,2,1,6,8,2,1],
       [0,1,3,5,1,2,9,2,1,7],
       [2,3,5,7,1,2,5,7,1,5]]) 

it should return

arr = ([[0,1,3,5,1,2,9,2,1,7],
        [0,3,1,4,2,1,6,8,2,1],
        [1,2,3,5,6,2,9,2,1,2],
        [2,3,5,7,1,2,5,7,1,5],
        [3,4,1,5,1,2,3,4,5,6]]) 
colt.exe
  • 708
  • 8
  • 24

1 Answers1

1

You can do the following:

arr[np.lexsort(np.flip(arr.transpose(), axis=0))]
Gorisanson
  • 2,202
  • 1
  • 9
  • 25