numpy array sorting weirdness

Daniel Fetchinson fetchinson at googlemail.com
Sat Mar 28 22:02:44 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

#################################################################


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



More information about the Python-list mailing list