[Numpy-discussion] Unfortunate user experience with max()

Anne Archibald peridot.faceted at gmail.com
Wed May 16 21:03:43 EDT 2007


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?

Thanks,
Anne M. Archibald



More information about the NumPy-Discussion mailing list