On Thu, Mar 24, 2011 at 6:19 AM, Ralf Gommers < ralf.gomm...@googlemail.com > wrote: > 2011/3/24 Dmitrey < tm...@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.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion