[SciPy-Dev] extended functionality of max/min ufuncs

Tom Grydeland tom.grydeland at gmail.com
Thu Aug 23 10:28:39 EDT 2012


Hi all,

I'm working on a system to translate (EXELIS/ITTVIS/RSI) IDL to
Python/Numpy.  The results are close to usable for many purposes, but
some simple constructs are causing snags I was hoping you could help
me with.

IDL's MAX function supports a second (output) argument which will
contain the index of the maximum value. One can write

PRINT, MAX(x, id), id

to get the value and index of the maximum element.  In Numpy, I could do

id = np.argmax(x); print x[id], id

to get the same results in two statements.  However, I can give MAX an
extra keyword /NAN to tell it to ignore NaN and infinities.  In Numpy,
I have np.nanmax, but no np.nanargmax.

In addition, MAX has the output keywords MIN=value and
SUBSCRIPT_MIN=index to return the minimum value and its index from the
same function call.  Similarly, MIN has output keywords MAX=value and
SUBSCRIPT_MAX=index, so I can get max/min values and their indices
(ignoring NaNs) in a single call -- in Numpy I would need two calls,
two indexing operations, one temporary array of values and one of
indices.

Would it be hard to add similar functionality to Numpy's min() and
max() functions?  Is it desirable?

Regards,

-- 
Tom Grydeland
  <Tom.Grydeland@(gmail.com)>



More information about the SciPy-Dev mailing list