sort array, apply rearrangement to second

Steve Holden steve at holdenweb.com
Wed Mar 31 01:56:25 CEST 2010


Victor Eijkhout wrote:
> I have two arrays, made with numpy. The first one has values that I want
> to use as sorting keys; the second one needs to be sorted by those keys.
> Obviously I could turn them into a dictionary  of pairs and sort by the
> first member, but I think that's not very efficient, at least in space,
> and this needs to be done as efficiently as possible.
> 
> I could use a hand.
> 
Well, my first approach would be to do it as inefficiently as I can ( or
at least no more efficiently than I can with a simple-minded approach)
and then take it from there.

If I believe this is not a premature optimization (a question about
which I am currently skeptical) I'd suggest conversion to a list of
pairs rather than a dict.

Can you use zip() on numpy arrays? That would be the easiest way to
create the list of pairs.

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/




More information about the Python-list mailing list