Sorting coordinates array

Ville Vainio ville.spammehardvainio at spamtut.fi
Fri Dec 19 06:01:05 EST 2003


Maarten van Reeuwijk <maarten at remove_this_ws.tn.tudelft.nl> writes:

> I'm a newbie to Python, so sorry for this maybe trivial question. I have a
> numpy array with coordinates, which I want to sort, for example first on
> z-coordinate, then x and lastly y-coordinate. So an array like:

Implement a comparison function:

>>> help([].sort)
Help on built-in function sort:

sort(...)
    L.sort(cmpfunc=None) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1


Alternatively, you could take a look at DSU pattern (Decorate, Sort,
Undecorate):

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234

-- 
Ville Vainio   http://www.students.tut.fi/~vainio24




More information about the Python-list mailing list