On 5/17/07, David M. Cooke <[EMAIL PROTECTED]> wrote:
On Wed, May 16, 2007 at 09:03:43PM -0400, Anne Archibald wrote: > Hi, > > Numpy has a max() function. It takes an array, and possibly some extra > arguments (axis and default). Unfortunately, this means that > > >>> numpy.max(-1.3,2,7) > -1.3 > > This can lead to surprising bugs in code that either explicitly > expects it to behave like python's max() or implicitly expects that by > doing "from numpy import max". > > I don't have a *suggestion*, exactly, for how to deal with this; > checking the type of the axis argument, or even its value, when the > first argument is a scalar, will still let some bugs slip through > (e.g., max(-1,0)). But I've been bitten by this a few times even once > I noticed it. > > Is there anything reasonable to do about this, beyond conditioning > oneself to use amax? 1) Don't do 'from numpy import max' :-) 2) 'from numpy import *' doesn't import max, so that's ok I don't think we can reasonably change that in a 1.0 release, but I'm all in favour of removing numpy.max in 1.1. Shadowing builtins is a bad idea. The same goes for numpy.sum, which, at the least, should be modified so that the function signatures are compatible: numpy.sum(x, axis=None, dtype=None, out=None) vs. sum(sequence, start=0)
For numpy.max at least, not accepting a fractional value as an axis would probably catch a large case of common errors. I mean it doesn't seem like it should be legal to say 'axis=2.7'. --bb
_______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
