Fast Sorting of n dimensional array by first dimension

Category: Python - Miscellaneous

I have looked far and wide for code for fast sorting of n dimensional arrays by the first element, for example if I had the array:
ray = [[1,2,3,7,5][10,11,12,13,14]]

I would want it to come out as
ray = [[1,2,3,5,7][10,11,12,14,13]]

There are several ways to do this. One is
zipped = zip(ray)
zipped.sort()
ray = zip(zipped)

but this is extremely slow. Numpy has a much faster way to do it, but it wasn't immediately apparent.

if the above were a numpy array you could simply do the following:
indexes = numpy.argsort(ray[0])
for n in xrange(len(ray))
ray[n] = ray[n][indexes]

I did a time test of the two methods below. Date: 12 April, 2012


Argsort - Lists - Numpy - Python - Sorting

Homepage: http://code.activestate.com/recipes/578074-fast-sorting-of-n-dimensional-array-by-first-dimen/?in=lang-python

Developer: Garrett

License: Freeware

Operating System: Windows

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

1st Email Searcher is Windows compatible.

developer Developer: http://www.softstack.com...
license License: Freeware
operating systems Operating System: Windows


Extract Emails is Windows compatible.

developer Developer: http://www.getfreefile.c...
license License: Freeware
operating systems Operating System: Windows


CoffeeCup Software aqcuired Dutch's HTML Software in March 2003 in an effort to combine the best of the Dutch' s with the CoffeeCup products to create more powerful tools and easier ways for people of all skill levels to create and manage websites.

developer Developer: http://www.dutchthewiz.c...
license License: Freeware
operating systems Operating System: Unix/Linux/Windows


Condense a Web page generated list of records into one page at a time.

developer Developer: dynamicreport.com
license License: Freeware
operating systems Operating System: All


Simple one file PHP Script.

developer Developer: alex hom
license License: Freeware
operating systems Operating System: unix


Email Subscriber Pro is intended for organizing subscription to mailing lists on websites.

developer Developer: Ixis Research LTD
license License: Freeware
operating systems Operating System: windows (any)


Subscription Manager - is a simplest, way to extract business emails from your regular POP 3 mailbox.

developer Developer: Emailarms
license License: Freeware
operating systems Operating System: Windows


This program is meant to act as an example of how to use ME with
data that needs to be obfuscated.

developer Developer: Stephen Chappell
license License: Freeware
operating systems Operating System: Windows


Oftentimes you want to find the index of a list-like object.

developer Developer: Garrett
license License: Freeware
operating systems Operating System: Windows