Efficient python 2-d arrays?
Robert Kern
robert.kern at gmail.com
Thu Jan 20 15:16:15 EST 2011
On 1/20/11 1:36 PM, Jake Biesinger wrote:
>> Thanks for the great suggestions!
>
> On a related note, is there no way to efficiently sort a python array?
No.
>>>> 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.
It's not really common. The array module is mostly used for data accumulation
and interchange. Most people who need to compute things over
efficiently-implemented homogeneous arrays use numpy.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list