简体   繁体   中英

Reverse sort a 2d numpy array in python

I have a numpy array like:

A = array([[-inf,  4,  5,  10, -inf, 1],
            [-inf,  2,  6, 8, -inf, 1],
            [-inf,  4,  -inf,  10, -inf, 100]
      ])

I need to sort in a decreasing order: 

A = array ([ 10,5,4,1,-inf,-inf], 
          [8,6,2,1,-inf,-inf],
           [100,10,4,-inf,-inf,-inf]])

Here -inf is float('-inf') How Do I do this?

I tried this: sorted(A, key=lambda listA: len(listA), reverse=True)

But I am not getting the sorted array. Can someone please tell me how to do this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM