[SciPy-dev] max and argmax

Robert Kern robert.kern@gmail....
Fri Aug 3 10:06:50 CDT 2007

dmitrey wrote:
> hi all,
> [val ind] = max(arr)
> returns both max and index of the max element.
> In Python I use
> ind = argmax(arr)
> val = arr(ind)
> is it possible to avoid 2 lines, i.e. somehow to replace by single one?

def matlablike_max(arr):
    ind = argmax(arr)
    return ind, arr[ind]

ind, val = matlablike_max(arr)

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the Scipy-dev mailing list