[SciPy-user] Finding Element Position and Sorting
Alan G Isaac
aisaac@american....
Sat Jan 12 10:27:51 CST 2008
Using `argsort` was a good suggestion.
More generally you can use a DSU pattern (e.g., below).
(I mention this since you speak of unspecified "objects";
it is not as useful for this specific example.)
Cheers,
Alan Isaac
>>> a = range(8)
>>> m = [1,1,0,2,2,0,2,1]
>>> from itertools import izip
>>> ag1 = [y for x,y in sorted(izip(m,a))]
>>> ag1
[2, 5, 0, 1, 7, 3, 4, 6]
>>> import numpy as N
>>> ag2 = N.fromiter((y for x,y in sorted(izip(m,a))),dtype='int')
>>> ag2
array([2, 5, 0, 1, 7, 3, 4, 6])
More information about the SciPy-user
mailing list