Re: [Numpy-discussion] buggy buggy bugyy: format and casting ==> BUG in numpy.sum?
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! Is that the expected behaviour or is the doc not updated? (I realise it may be better to force axis=.. to indicate what you need but still.. the example in numpy.sum help gives: sum([[0, 1], [0, 5]]) array([0, 6]) which is not what it gives when you do it...) thanks Eric
Hey Eric
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!
The problem is that the sum axis default is None, not 0.
Is that the expected behaviour or is the doc not updated? (I realise it may be better to force axis=.. to indicate what you need but still.. the example in numpy.sum help gives: sum([[0, 1], [0, 5]]) array([0, 6]) which is not what it gives when you do it...)
The documentation seems to be outdated. I'm not sure, but I think a few of the axis default might have changed in the not too distant past. Not sure if sum was affected. Either way, could you please file a ticket? http://projects.scipy.org/scipy/numpy/register http://projects.scipy.org/scipy/numpy/newticket Regards, Albert
Eric Emsellem schrieb:
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!
The default axis was changed recently to None (btw, which version are you using?), see the release notes on the web. So yes, it's expected.
Is that the expected behaviour or is the doc not updated? (I realise it may be better to force axis=.. to indicate what you need but still.. the example in numpy.sum help gives: sum([[0, 1], [0, 5]]) array([0, 6]) which is not what it gives when you do it...)
on my 1.0b5 I also see this docstring which indeed seems obsolete. Has it been changed since then? (And similarly for the other functions/methods where axis arguments have changed.) I could check the docstrings systematically and update them, but unfortunately not before the end of this month, sorry. cheers, sven
Sven Schreiber wrote:
on my 1.0b5 I also see this docstring which indeed seems obsolete.
I get this docs string from :
import numpy as N N.__version__ '1.0b5' a = N.arange(10) help( a.sum)
""" sum(...) a.sum(axis=None, dtype=None) -> Sum of array over given axis. Sum the array over the given axis. If the axis is None, sum over all dimensions of the array. """ that looks right to me. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
Christopher Barker schrieb:
Sven Schreiber wrote:
on my 1.0b5 I also see this docstring which indeed seems obsolete.
I get this docs string from :
import numpy as N N.__version__ '1.0b5' a = N.arange(10) help( a.sum)
""" sum(...) a.sum(axis=None, dtype=None) -> Sum of array over given axis.
Sum the array over the given axis. If the axis is None, sum over all dimensions of the array.
"""
that looks right to me.
-Chris
Well here's what we had in mind: sum(x, axis=None, dtype=None, out=None) (...) Examples: >>> sum([0.5, 1.5]) 2.0 >>> sum([0.5, 1.5], dtype=Int32) 1 >>> sum([[0, 1], [0, 5]]) array([0, 6]) >>> sum([[0, 1], [0, 5]], axis=1) array([1, 5]) And you can see the third example would now be wrong, giving a scalar of 6 now. -sven
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
participants (5)
-
Albert Strasheim
-
Christopher Barker
-
Eric Emsellem
-
Sven Schreiber
-
Travis Oliphant