Efficient python 2-d arrays?

Dan Stromberg drsalists at gmail.com
Thu Jan 20 15:48:37 EST 2011


On Thu, Jan 20, 2011 at 11:36 AM, Jake Biesinger
<jake.biesinger at gmail.com> wrote:
>> Thanks for the great suggestions!
>
> On a related note, is there no way to efficiently sort a python array?
>
>
>>>> x = array('f', xrange(10000000))
>>>> x.sort()
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
>
> /home/wbiesing/src/python-sort/<ipython console> in <module>()
>
> AttributeError: 'array.array' object has no attribute 'sort'
>
>>>> type(sorted(x))
> <type 'list'>
>
> Seems like a common enough task, but no way to do it efficiently without scipy/numpy.

Tap, tap: Is this thing on?  I keep sending messages to this list, but
no one seems to "hear" what I'm writing.

Anyway, I have a bunch of sorts in python (pure or cython, your
option) at http://stromberg.dnsalias.org/cgi-bin/viewvc.cgi/sorts/compare/trunk/?root=svn

The pure python versions should all work out of the box with an
array.array.  I tested the timsort on an array.array, and it worked
well.

Also, I just made a trivial modification (not checked in! ...but I did
test it) to make the cythonized timsort support sorting arrays - just
change the "list" type declarations to "object" (or perhaps
"array.array") prior to compiling.

I also just changed the license on them from GPL v3 to Apache v2.

timsort truly is a somewhat supernatural algorithm.



More information about the Python-list mailing list