numpy array sorting weirdness

Daniel Fetchinson fetchinson at googlemail.com
Sat Mar 28 22:13:49 EDT 2009


>> So far I was working under the assumption that the numpy array
>> implementation can be used as a drop-in replacement for native python
>> lists, i.e. wherever I see a list 'a' and I want to speed up my
>> numerical calculations I just replace it with 'numpy.array( a )' and
>> everything will work just as before. It took me about half a day to
>> track down a bug which was a result of this assumption being wrong.
>>
>> The fact that the following two outputs are not the same is a bug or a
>> feature of numpy?
>>
>> ##### I would have thought the two array outputs would be the same ######
>>
>> import numpy
>>
>> a = [ [ 0, 0 ], [ 1, 0 ], [ 1, 1 ] ]
>>
>> pythonarray = a
>> pythonarray.sort( )
>> print pythonarray
>>
>> numpyarray = numpy.array( a )
>> numpyarray.sort( )
>> print numpyarray
>>
>> #################################################################
>
>
> What is the output?
>

In the first case: [[0, 0], [1, 0], [1, 1]]
While in the second: [[0, 0], [0, 1], [1, 1]]

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown



More information about the Python-list mailing list