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
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
>
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(
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]
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)
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
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
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 =
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
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
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).
--
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
"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
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
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
15 matches
Mail list logo