[Numpy-discussion] min() of array containing NaN

Joe Harrington jh@physics.ucf....
Wed Aug 13 14:37:09 CDT 2008


>On Tue, Aug 12, 2008 at 19:28, Charles R Harris
><charlesr.harris@gmail.com> wrote:
>>
>>
>> On Tue, Aug 12, 2008 at 5:13 PM, Andrew Dalke <dalke@dalkescientific.com>
>> wrote:
>>>
>>> On Aug 12, 2008, at 9:54 AM, Anne Archibald wrote:
>>> > Er, is this actually a bug? I would instead consider the fact that
>>> > np.min([]) raises an exception a bug of sorts - the identity of min is
>>> > inf.
>>
>> <snip>
>>
>>>
>>> Personally, I expect that if my array 'x' has a NaN then
>>> min(x) must be a NaN.
>>
>> I suppose you could use
>>
>> min(a,b) = (abs(a - b) + a + b)/2
>>
>> which would have that effect.

>Or we could implement the inner loop of the minimum ufunc to return
>NaN if there is a NaN. Currently it just compares the two values
>(which causes the unpredictable results since having a NaN on either
>side of the < is always False). I would be amenable to that provided
>that the C isnan() call does not cause too much slowdown in the normal
>case.

While you're doing that, can you do it so that if keyword nan=False it
returns NaN if NaNs exist, and if keyword nan=True it ignores NaNs?
We can argue which should be the default (see my prior post).  Both
are compatible with the current undefined behavior.

I assume that the fastest way to do it is two separate loops for the
separate cases, but it might be fast enough straight (with a
conditional in the inner loop), or with some other trick (macro magic,
function pointer, whatever).

Thanks,

--jh--


More information about the Numpy-discussion mailing list