[Numpy-discussion] buggy buggy bugyy: format and casting ==> BUG in numpy.sum?

Travis Oliphant oliphant.travis at ieee.org
Mon Sep 18 14:52:24 EDT 2006


Eric Emsellem wrote:
> Hi again
>
> after some hours of debugging I finally (I think) found the problem:
>
> numpy.sum([[0,1,2],[2,3,4]])
> 24
>
> numpy.sum([[0,1,2],[2,3,4]],axis=0)
> array([2, 4, 6])
>
> numpy.sum([[0,1,2],[2,3,4]],axis=1)
> array([3, 9])
>
>
> Isn't the first line supposed to act as with "axis=0" by default (see
> help numpy.sum!)...???
> Not setting axis=0 it sums everything!
>   
See the Release Notes page on www.scipy.org.  It documents everything 
that has changed.  Several things will break old code as indicated. 

There are several options for keeping old code working:

1) Use the numpy.oldnumeric compatibility layer which keeps the same 
definitions and defaults as Numeric

2) Use conversion tools (like the recently added fix_default_axis) tool 
to automatically insert axis=0 arguments in all code where it is not 
present (or to automatically change the import to oldnumeric).

For the future, you must specify which axis you mean for a Nd array or 
the code will assume you meant to work over the entire N-d array.

We all recognize this is a pain to change.  That's why the backward 
compatibilty options are avaiable and the tools have been written.  
Believe me, I know what a pain it is.  I have had to keep SciPy and 
Matplotlib working with all the changes to NumPy. 



-Travis






More information about the NumPy-Discussion mailing list