numpy array sorting weirdness

D

Daniel Fetchinson

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top