[Numpy-discussion] argmin and argmax without nan
Thu Mar 24 13:02:58 CDT 2011
On Thu, Mar 24, 2011 at 6:19 AM, Ralf Gommers
email@example.com > wrote:
> 2011/3/24 Dmitrey < firstname.lastname@example.org >:
>> is there any way to get argmin and argmax of an array w/o nans?
>> Currently I have
>>>>> from numpy import *
>> But it's not the values I would like to get.
>> The walkaround I use: get all indeces of nans, replace them by -inf, get
>> argmax, replace them by inf, get argmin.
>> Is there any better way? (BTW, I invoke argmin/argmax along of a chosen
> In : np.nanargmax([10, np.nan, 100])
> Out: 2
> In : np.nanargmin([10, np.nan, 100])
> Out: 0
And if speed is an issue (it usually isn't) you can use the nanargmax
>> a = np.random.rand(10000)
>> a[a > 0.5] = np.nan
>> timeit np.nanargmax(a)
10000 loops, best of 3: 127 us per loop
>> import bottleneck as bn
>> timeit bn.nanargmax(a)
100000 loops, best of 3: 12.4 us per loop
For some problems some % speedup could be yielded.
Are there any plans for merging bottleneck into numpy?
Also, are those benchmarks valid for ordinary numpy only or numpy with
MKL/ACML or it doesn't matter?
If I have huge arrays and multicore CPU, will numpy with MKL/ACML or
something else involve parallel computations with numpy funcs like
amin, amax, argmin, nanargmin etc?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion