Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- l = [0,-8,1,10,13,2]
- a = np.argsort(l)
- # returns [1 0 2 5 3 4], the order required to sort l
- # init new list to zero
- pos = [0 for x in range(0,len(l))]
- # scatter http://en.wikipedia.org/wiki/Gather-scatter_(vector_addressing)
- for i in range(0,len(l)):
- pos[a[i]] = i
- print pos
- # prints [1, 0, 2, 4, 5, 3], i.e. each original indexes new position in the sorted array
- import numpy as np
- l = np.array([0,-8,1,10,13,2])
- def myargsort(numbers):
- tuples = enumerate(numbers) # returns iterable of index,value
- return np.array([idx for idx,val in sort(tuples,key = lambda pair: pair[1])])
- print(l)
- print(myargsort(l))
- print(np.argsort(l))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement