nlcpy.amax

nlcpy.amax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)[source]

Returns the maximum of an array or maximum along an axis.

Parameters
aarray_like

Array containing numbers whose maximum is desired. If a is not an array, a conversion is attempted.

axisNone or int or tuple of ints, optional

Axis or axes along which to operate. By default, flattened input is used. If this is a tuple of ints, the maximum is selected over multiple axes.

outndarray, optional

Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.

keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

initialscalar, optional

The maximum value of an output element. Must be present to allow computation on empty slice. See nlcpy.ufunc.reduce() for details.

wherearray_like of bool, optional

Elements to compare for the maximum. See nlcpy.ufunc.reduce() for details.

Returns
amaxndarray

Maximum of a. An array with the same shape as a, with the specified axis removed. If a is a scalar, or if axis is None, this function returns the result as a 0-dimention array. The same dtype as a is returned.

See also

amin

Returns the minimum of an array or minimum along an axis.

nanmax

Returns maximum of an array or maximum along an axis, ignoring any NaNs.

maximum

Element-wise maximum of array elements.

fmax

Element-wise maximum of array elements.

argmax

Returns the indices of the maximum values along an axis.

nanmin

Returns the minimum of an array or minimum along an axis, ignoring any NaNs.

minimum

Element-wise minimum of array elements.

fmin

Element-wise minimum of array elements.

Note

NaN values are propagated, that is if at least one item is NaN, the corresponding max value will be NaN as well. To ignore NaN values, please use nanmax.

Don’t use amax() for element-wise comparison of 2 arrays; when a.shape[0] is 2, maximum(a[0], a[1]) is faster than amax(a, axis=0).

Restriction

  • If an ndarray is passed to where and where.shape != a.shape, NotImplementedError occurs.

  • If an ndarray is passed to out and out.shape != amax.shape, NotImplementedError occurs.

Examples

>>> import nlcpy as vp
>>> a = vp.arange(4).reshape((2,2))
>>> a
array([[0, 1],
       [2, 3]])
>>> vp.amax(a)           # Maximum of the flattened array
array(3)
>>> vp.amax(a, axis=0)   # Maxima along the first axis
array([2, 3])
>>> vp.amax(a, axis=1)   # Maxima along the second axis
array([1, 3])
>>> b = vp.arange(5, dtype=float)
>>> b[2] = vp.NaN
>>> vp.amax(b)
array(nan)
>>> vp.amax(b, where=~vp.isnan(b), initial=-1)
array(4.)
>>> vp.nanmax(b)
array(4.)