[Numpy-discussion] argmin and argmax without nan
Dmitrey
tmp50@ukr....
Thu Mar 24 13:02:58 CDT 2011
On Thu, Mar 24, 2011 at 6:19 AM, Ralf Gommers
<
ralf.gommers@googlemail.com > wrote:
> 2011/3/24 Dmitrey < tmp50@ukr.net >:
>> hi,
>> is there any way to get argmin and argmax of an array w/o nans?
>> Currently I have
>>>>> from numpy import *
>>>>> argmax([10,nan,100])
>> 1
>>>>> argmin([10,nan,100])
>> 1
>> 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
>> axis)
>> D.
>
> In [3]: np.nanargmax([10, np.nan, 100])
> Out[3]: 2
>
> In [4]: np.nanargmin([10, np.nan, 100])
> Out[4]: 0
And if speed is an issue (it usually isn't) you can use the nanargmax
from Bottleneck:
>> 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?
D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110324/6449284a/attachment.html
More information about the NumPy-Discussion
mailing list