python - Sorting numpy lists -


i having troubles working numpy arrays new numpy. have big input read sys.stdin, consisted of lines 2 values , space between them, representing point or 2 coordinates. save in list looks this:

np.array([[1, 3], [5, 6], [7, 2], [9, 9]]) 

i want sort list sums , x-coordinate, not sure how this.

i not sure how add sum third element of each sublist, in case wanted add it.

relying on python's built-in sorted inefficient numpy-arrays, when these big. try instead:

import numpy np  l = np.array([[1, 3], [5, 6], [7, 2], [9, 9]])  ind = np.lexsort((l[:,0], l.sum(axis=1)))  sorted_l = l[ind] 

ind contain indices of original array, sorted 2 arrays given lexsort. last array primary sort column lexsort. l[ind] selects these indices original array.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -