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's cleaner (and more

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 = [5, 8, 2, 11, 6] >>>

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 thinking. 2. The particular use

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 the) first ma

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). -- Alexandre Fayolle

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 this a good argmax (as lon

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 max(izip( iterable, count() > ))[1] >

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 repeatedly remove the largest