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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -