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

Keith Goodman kwgoodman@gmail....
Fri Nov 19 14:29:00 CST 2010


On Fri, Nov 19, 2010 at 12:19 PM, Pauli Virtanen <pav@iki.fi> wrote:
> Fri, 19 Nov 2010 11:19:57 -0800, Keith Goodman wrote:
> [clip]
>> My guess is that having separate underlying functions for each dtype,
>> ndim, and axis would be a nightmare for a large project like Numpy. But
>> manageable for a focused project like nanny.
>
> Might be easier to migrate the nan* functions to using Ufuncs.
>
> Unless I'm missing something,
>
>        np.nanmax -> np.fmax.reduce
>        np.nanmin -> np.fmin.reduce
>
> For `nansum`, we'd need to add an ufunc `nanadd`, and for
> `nanargmax/min`, we'd need `argfmin/fmax'.

How about that! I wasn't aware of fmax/fmin. Yes, I'd like a nanadd, please.

>> arr = np.random.rand(1000, 1000)
>> arr[arr > 0.5] = np.nan
>> np.nanmax(arr)
   0.49999625409581072
>> np.fmax.reduce(arr, axis=None)
<snip>
TypeError: an integer is required
>> np.fmax.reduce(np.fmax.reduce(arr, axis=0), axis=0)
   0.49999625409581072

>> timeit np.fmax.reduce(np.fmax.reduce(arr, axis=0), axis=0)
100 loops, best of 3: 12.7 ms per loop
>> timeit np.nanmax(arr)
10 loops, best of 3: 39.6 ms per loop

>> timeit np.nanmax(arr, axis=0)
10 loops, best of 3: 46.5 ms per loop
>> timeit np.fmax.reduce(arr, axis=0)
100 loops, best of 3: 12.7 ms per loop


More information about the NumPy-Discussion mailing list