On 6/30/22, Ewout ter Hoeven <e.m.terhoe...@student.tudelft.nl> wrote:
> A function to get the minimum and maximum values of an array simultaneously
> could be very useful, from both a convenience and performance point of view.
> Especially when arrays get larger the performance benefit could be
> significant, and even more if the array doesn't fit in L2/L3 cache or even
> memory.
>
> There are many cases where not either the minimum or the maximum of an array
> is required, but both. Think of clipping an array, getting it's range,
> checking for outliers, normalizing, making a plot like a histogram, etc.
>
> This function could be called aminmax() for example, and also be called like
> ndarray.minmax(). It should return a tuple (min, max) with the minimum and
> maximum values of the array, identical to calling (ndarray.min(),
> ndarray.max()).
>
> With such a function, numpy.ptp() and the special cases of numpy.quantile(a,
> q=[0,1]) and numpy.percentile(a, q=[0,100]) could also potentially be
> speeded up, among others.
>
> Potentially argmin and argmax could get the same treatment, being called
> argminmax().
>
> There is also a very extensive post on Stack Overflow (a bit old already)
> with discussion and benchmarks:
> https://stackoverflow.com/questions/12200580/numpy-function-for-simultaneous-max-and-min


FYI, I have a fairly simple gufunc implementation of `minmax` in
ufunclab (https://github.com/WarrenWeckesser/ufunclab),  along with
`arg_minmax`, `min_argmin` and `max_argmax`.  See README.md starting
here: https://github.com/WarrenWeckesser/ufunclab#minmax

For those familiar with C and gufunc implementation details, you can
find the implementations in
https://github.com/WarrenWeckesser/ufunclab/blob/main/src/minmax/minmax_gufunc.c.src.
  You'll see that, as far as gufuncs go, these are not very
sophisticated.  They do not include implementations for all the NumPy
data types, and  I haven't yet spent much time on optimization.

Warren


> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: warren.weckes...@gmail.com
>
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to