[Numpy-discussion] Medians that ignore values

David Cournapeau david@ar.media.kyoto-u.ac...
Fri Sep 19 04:20:56 CDT 2008


Stéfan van der Walt wrote:
>
> So am I.  In all my use cases, NaNs indicate trouble.

Yes, so I would like to  have the opinion of people with other usage
than ours.
>
> Because we have x.max() silently ignoring NaNs, which causes a lot of
> head-scratching, swearing and failed experiments.

But cannot this be fixed at the python level of the max function ? I
think it is expected to have the low level C functions to ignore/be
bogus if you have Nan. After all, if you use sort of the libc with nan,
or sort in C++ for a vector of double, it will not work either.

But on my numpy, it looks like nan breaks min/max, they are not ignored:

np.min(np.array([0, np.nan, 1]))
-> 1.0 # bogus

np.min(np.array([0, np.nan, 2]))
-> 2.0 # ok

np.min(np.array([0, np.nan, -1]))
-> -1.0 # ok

np.max(np.array([0, np.nan, -1]))
> -1.0 # bogus

Which only makes sense when you guess how they are implemented in C...

cheers,

David


More information about the Numpy-discussion mailing list