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?
How about
A.sort()
A[:,::-1]
?
References :
http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.sort.html
http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
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.