Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python numpy sort 1D array

I am trying to sort a numpy array using this very simple code:

print np.array([2,0,8,4,1]).sort()

However, I am getting the result:

None

Can someone tell me what's going on here?

like image 437
user1220022 Avatar asked Sep 12 '25 20:09

user1220022


1 Answers

The array probably gets sorted in-place, like Python's list.sort() does so you don't get fooled into thinking the original array is still the same.

arr = np.array([2,0,8,4,1])
arr.sort()
print arr
like image 104
AKX Avatar answered Sep 15 '25 09:09

AKX