[Numpy-discussion] [ANN] Nanny, faster NaN functions

josef.pktd@gmai... josef.pktd@gmai...
Fri Nov 19 22:33:11 CST 2010


On Fri, Nov 19, 2010 at 10:59 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Fri, Nov 19, 2010 at 7:51 PM,  <josef.pktd@gmail.com> wrote:
>>
>> does this give you the correct answer?
>>
>>>>> 1>np.nan
>> False
>>
>> What's the starting value for amax? -inf?
>
> Because "1 > np.nan" is False, the current running max does not get
> updated, which is what we want.
>
>>> import nanny as ny
>>> np.nanmax([1, np.nan])
>   1.0
>>> np.nanmax([np.nan, 1])
>   1.0
>>> np.nanmax([np.nan, 1, np.nan])
>   1.0
>
> Starting value is -np.inf for floats and stuff like this for ints:
>
> cdef np.int32_t MININT32 = np.iinfo(np.int32).min
> cdef np.int64_t MININT64 = np.iinfo(np.int64).min

That's what I thought halfway through typing the question.

>>> -np.inf>-np.inf
False

If the only value is -np.inf, you will return nan, I guess.

>>> np.nanmax([-np.inf, np.nan])
-inf

Josef
(being picky)

>
> Numpy does this:
>
>>> np.nanmax([])
> <snip>
> ValueError: zero-size array to ufunc.reduce without identity
>
> Nanny does this:
>
>>> ny.nanmax([])
>   nan
>
> So I haven't taken care of that corner case yet. I'll commit nanmax to
> github in case anyone wants to give it a try.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list