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

后端 未结 12 874
天涯浪人
天涯浪人 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:27

    There is a function for finding (max-min) called numpy.ptp if that's useful for you:

    >>> import numpy
    >>> x = numpy.array([1,2,3,4,5,6])
    >>> x.ptp()
    5
    

    but I don't think there's a way to find both min and max with one traversal.

    EDIT: ptp just calls min and max under the hood

提交回复
热议问题