[Python-ideas] Re: argmax and argmin to python list

2020-08-31 Thread Robin Becker
On 31/08/2020 01:14, Christopher Barker wrote: or use numpy:-) (which is probably where the name "argmin" came from, rather than "index_min") https://en.wikipedia.org/wiki/Arg_max not sure if numpy precedes my own first memory of these functions in the 1970's, but it's fairly obvious that

[Python-ideas] Re: argmax and argmin to python list

2020-08-31 Thread Jeff Allen
On 31/08/2020 01:14, Christopher Barker wrote: On Sun, Aug 30, 2020 at 7:28 AM Barry > wrote: How is it supposed to work with set or dict or other iterables without clear order? see the discussion in another recent thread about making dict indexable --

[Python-ideas] Re: argmax and argmin to python list

2020-08-31 Thread Antoine Pitrou
On Sun, 30 Aug 2020 09:51:14 +0100 Barry Scott wrote: > That is 4x slower then my code for 1,000,000 items. This is highly dependent on the cost of equality checks, therefore on the type being compared. Regards Antoine. ___ Python-ideas mailing list

[Python-ideas] Re: argmax and argmin to python list

2020-08-30 Thread Christopher Barker
On Sun, Aug 30, 2020 at 7:28 AM Barry wrote: > How is it supposed to work with set or dict or other iterables without > clear order? > > see the discussion in another recent thread about making dict indexable -- which looks like it's not going to happen. so no -- this should not work with

[Python-ideas] Re: argmax and argmin to python list

2020-08-30 Thread Barry
> On 30 Aug 2020, at 12:25, Filipp Bakanov wrote: > >  > It's expected that python single iterating would be slower than two times C > iterating. Nevertheless one time C iterating will be probably faster than a > separate min + index. > > >> I think one would want argmin() and argmax() to

[Python-ideas] Re: argmax and argmin to python list

2020-08-30 Thread Jeff Allen
On 30/08/2020 09:51, Barry Scott wrote: >>> a.index(max(a)) 1 Barry This has the drawback of passing twice over the list. The following doesn't, but the complexity somewhat makes Filipp's point: >>> min((e, i) for i, e in enumerate(a))[1] 0 That is 4x slower then my code for 1,000,000

[Python-ideas] Re: argmax and argmin to python list

2020-08-30 Thread Filipp Bakanov
It's expected that python single iterating would be slower than two times C iterating. Nevertheless one time C iterating will be probably faster than a separate min + index. >> I think one would want argmin() and argmax() to work with general iterables How is it supposed to work with set or dict

[Python-ideas] Re: argmax and argmin to python list

2020-08-30 Thread Barry Scott
> On 30 Aug 2020, at 09:03, Jeff Allen wrote: > > On 29/08/2020 14:17, Barry Scott wrote: >>> On 29 Aug 2020, at 13:42, Filipp Bakanov >> > wrote: >>> >>> I'd like to propose adding argmax and argmin functions to the python list. >>> These functions return the index

[Python-ideas] Re: argmax and argmin to python list

2020-08-30 Thread Jeff Allen
On 29/08/2020 14:17, Barry Scott wrote: On 29 Aug 2020, at 13:42, Filipp Bakanov > wrote: I'd like to propose adding argmax and argmin functions to the python list. These functions return the index of a maximum / minimum element of the list. Eg: a = [1, 4, 2, 3]

[Python-ideas] Re: argmax and argmin to python list

2020-08-29 Thread Barry Scott
> On 29 Aug 2020, at 13:42, Filipp Bakanov wrote: > > I'd like to propose adding argmax and argmin functions to the python list. > These functions return the index of a maximum / minimum element of the list. > Eg: > > a = [1, 4, 2, 3] > print(a.argmax()) # 1 > print(a.argmin()) # 0 > >