min, max with position

Alan Bawden alan at csail.mit.edu
Sat Jun 4 16:16:13 EDT 2022


"Michael F. Stemper" <michael.stemper at gmail.com> writes:

   Are there similar functions that return not only the minimum
   or maximum value, but also its position?

    >>> specialmin(l)
    (0,1.618033)
    >>> specialmax(l)
    3.141593
    >>>

I believe that what you are looking for is usually called "argmax" and
"argmin" (see <en.wikipedia.org/wiki/Arg_max>).  These don't exist in
the standard Python library as far as I can tell, but numpy does have
"argmax" and "argmin" routines.

-- 
Alan Bawden


More information about the Python-list mailing list