Monday, October 22, 2018

Max function in Python


np.max is just an alias for np.amax. This function only works on a single input array and finds the value of maximum element in that entire array (returning a scalar). Alternatively, it takes an axisargument and will find the maximum value along an axis of the input array (returning a new array).

>>> a = np.array([[1, 2, 6],
                  [2, 4, 1]])
>>> np.max(a)
6
>>> np.max(a, axis=0) # max of each column
array([2, 4, 6])


np.maximum will take two arrays and compute their element-wise maximum. Arrays should be compatible. Below is an example:

>>> b = np.array([3, 6, 1])
>>> c = np.array([4, 2, 9])
>>> np.maximum(b, c)
array([4, 6, 9])

No comments:

Post a Comment