NumPy: function for simultaneous max() and min()

后端 未结 12 910
天涯浪人
天涯浪人 2020-11-27 04:54

numpy.amax() will find the max value in an array, and numpy.amin() does the same for the min value. If I want to find both max and min, I have to call both functions, which

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 05:26

    At first glance, numpy.histogram appears to do the trick:

    count, (amin, amax) = numpy.histogram(a, bins=1)
    

    ... but if you look at the source for that function, it simply calls a.min() and a.max() independently, and therefore fails to avoid the performance concerns addressed in this question. :-(

    Similarly, scipy.ndimage.measurements.extrema looks like a possibility, but it, too, simply calls a.min() and a.max() independently.

提交回复
热议问题