Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import numpy as np
  2.  
  3. l = [0,-8,1,10,13,2]
  4.  
  5. a = np.argsort(l)
  6. # returns [1 0 2 5 3 4], the order required to sort l
  7.  
  8. # init new list to zero
  9. pos = [0 for x in range(0,len(l))]
  10.  
  11. # scatter http://en.wikipedia.org/wiki/Gather-scatter_(vector_addressing)
  12. for i in range(0,len(l)):
  13. pos[a[i]] = i
  14.  
  15. print pos
  16. # prints [1, 0, 2, 4, 5, 3], i.e. each original indexes new position in the sorted array
  17.  
  18. import numpy as np
  19.  
  20. l = np.array([0,-8,1,10,13,2])
  21.  
  22. def myargsort(numbers):
  23. tuples = enumerate(numbers) # returns iterable of index,value
  24. return np.array([idx for idx,val in sort(tuples,key = lambda pair: pair[1])])
  25.  
  26. print(l)
  27. print(myargsort(l))
  28. print(np.argsort(l))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement