[Numpy-discussion] Behavior of nan{max, min} and nanarg{max, min} for all-nan slices.

Charles R Harris charlesr.harris at gmail.com
Wed Oct 2 15:19:27 EDT 2013


On Wed, Oct 2, 2013 at 12:51 PM, <josef.pktd at gmail.com> wrote:

> On Wed, Oct 2, 2013 at 2:49 PM,  <josef.pktd at gmail.com> wrote:
> > On Wed, Oct 2, 2013 at 2:05 PM, Stéfan van der Walt <stefan at sun.ac.za>
> wrote:
> >> On 2 Oct 2013 19:14, "Benjamin Root" <ben.root at ou.edu> wrote:
> >>>
> >>> And it is logically consistent, I think.  a[nanargmax(a)] == nanmax(a)
> >>> (ignoring the silly detail that you can't do an equality on nans).
> >>
> >> Why do you call this a silly detail? It seems to me a fundamental flaw
> to
> >> this approach.
> >
> > a nan is a nan is a NaN
> >
> >>>> np.testing.assert_equal([0, np.nan], [0, np.nan])
> >>>>
>
> and the functions have "nan" in their names
> nan in - NaN out
>
> what about nanmean, nansum, ...?
>

nanmean returns nan for empty slices while nansum returns nan in 1.8,
consistent with previous behavior, and will return 0 in 1.9.

The main problem I had was deciding what arg{max, min} should return as the
return value is an integer. I like your suggestion of returning 0.

One further possibility is to add a keyword 'raise' to make the behavior
selectable.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131002/22f1a7f6/attachment.html>


More information about the NumPy-Discussion mailing list