Re: Request for argmax(list) and argmin(list)

2021-09-02 Thread Dan Stromberg
l.index(min(l)) > > 0 > > On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote: > > > I dont want to import numpy > > > > > > argmax(list) > > > returns index of (left most) max element > > > > > > argmin(list) > > > returns index of (left most) min element > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list

Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread Calvin Spealman
0 > > On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote: > > > I dont want to import numpy > > > > > > argmax(list) > > > returns index of (left most) max element > > > > > > argmin(list) > > > returns index of (left most) min element >

Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread ABCCDE921
gt; >>> l.index(max(l)) > 3 > >>> l.index(min(l)) > 0 > On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote: > > I dont want to import numpy > > > > argmax(list) > > returns index of (left most) max element > > > > argmin(

Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread Peter Otten
On 01/09/2021 06:25, ABCCDE921 wrote: I dont want to import numpy argmax(list) returns index of (left most) max element >>> import operator >>> second = operator.itemgetter(1) >>> def argmax(values): return max(enumerate(values), key=second)[0]

Re: Request for argmax(list) and argmin(list)

2021-08-31 Thread Paul Bryan
Why not: >>> l = [1, 3, 5, 9, 2, 7] >>> l.index(max(l)) 3 >>> l.index(min(l)) 0 On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote: > I dont want to import numpy > > argmax(list) >    returns index of (left most) max element > >  argmin(list)

Request for argmax(list) and argmin(list)

2021-08-31 Thread ABCCDE921
I dont want to import numpy argmax(list) returns index of (left most) max element argmin(list) returns index of (left most) min element -- https://mail.python.org/mailman/listinfo/python-list

Re: argmax

2006-06-01 Thread Ben Cartwright
David Isaac wrote: > 2. Is this a good argmax (as long as I know the iterable is finite)? > def argmax(iterable): return max(izip( iterable, count() ))[1] Other than the subtle difference that Peter Otten pointed out, that's a good method. However if the iterable is a list, it

Re: argmax

2006-06-01 Thread Steven Bethard
David Isaac wrote: > 2. Is this a good argmax (as long as I know the iterable is finite)? > def argmax(iterable): return max(izip( iterable, count() ))[1] In Python 2.5: Python 2.5a2 (trunk:46491M, May 27 2006, 14:43:55) [MSC v.1310 32 bit (Intel)] on win32 >>> iterable =

Re: argmax

2006-06-01 Thread David Isaac
Thanks for all the replies. A couple of comments. 1. I think the usefulness of an argmax built-in can be assessed by looking at other languages (and e.g. at numpy). So I do not buy the "not needed" argument as presented. More like "haven't got around to it," I'm th

Re: argmax

2006-06-01 Thread Peter Otten
David Isaac wrote: > 2. Is this a good argmax (as long as I know the iterable is finite)? > def argmax(iterable): return max(izip( iterable, count() ))[1] There's a subtle difference to the builtin: argmax() gives you the (index of the) last maximum while max() returns the (value of

Re: argmax

2006-06-01 Thread Alexandre Fayolle
Le 01-06-2006, David <[EMAIL PROTECTED]> nous disait: > 1. Why is there no argmax built-in? > (This would return the index of the largest element in a sequence.) You'll get argmin and argmax in Numeric and its descendants (numarray and numpy). --

Re: argmax

2006-06-01 Thread George Sakkis
David Isaac wrote: > 1. Why is there no argmax built-in? > (This would return the index of the largest element in a sequence.) I guess because it's not used frequently enough. I've needed argmax/argmin more than once though, so I would welcome them as builtins. > 2. Is thi

Re: argmax

2006-06-01 Thread Max Erickson
"David Isaac" <[EMAIL PROTECTED]> wrote: > 1. Why is there no argmax built-in? > (This would return the index of the largest element in a > sequence.) > > 2. Is this a good argmax (as long as I know the iterable is > finite)? def argmax(iterable): return

Re: argmax

2006-06-01 Thread Duncan Booth
David Isaac wrote: > 1. Why is there no argmax built-in? > (This would return the index of the largest element in a sequence.) Probably there isn't a built-in because it isn't a commonly needed function. What is your use-case for argmax? If for example you want to repeat

argmax

2006-06-01 Thread David Isaac
1. Why is there no argmax built-in? (This would return the index of the largest element in a sequence.) 2. Is this a good argmax (as long as I know the iterable is finite)? def argmax(iterable): return max(izip( iterable, count() ))[1] 3. If this is the only place in a module where I need count