numpy.ma.max — NumPy v2.6.dev0 Manual

ma.max(obj, axis=None, out=None, fill_value=None, keepdims=<novalue>)

[source]

#

Return the maximum along a given axis.

Parameters:axisNone or int or tuple of ints, optionalAxis along which to operate. By default, axis is None and the flattened input is used. If this is a tuple of ints, the maximum is selected over multiple axes, instead of a single axis or all the axes as before.

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

fill_valuescalar or None, optionalValue used to fill in the masked values. If None, use the output of maximum_fill_value().

keepdimsbool, optionalIf 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 array.

Returns:amaxarray_likeNew array holding the result. If out was specified, out is returned.

Examples

>>> importnumpy.maasma>>> x=[[-1.,2.5],[4.,-2.],[3.,0.]]>>> mask=[[0,0],[1,0],[1,0]]>>> masked_x=ma.masked_array(x,mask)>>> masked_xmasked_array( data=[[-1.0, 2.5], [--, -2.0], [--, 0.0]], mask=[[False, False], [ True, False], [ True, False]], fill_value=1e+20)>>> ma.max(masked_x)2.5>>> ma.max(masked_x,axis=0)masked_array(data=[-1.0, 2.5], mask=[False, False], fill_value=1e+20)>>> ma.max(masked_x,axis=1,keepdims=True)masked_array( data=[[2.5], [-2.0], [0.0]], mask=[[False], [False], [False]], fill_value=1e+20)>>> mask=[[1,1],[1,1],[1,1]]>>> masked_x=ma.masked_array(x,mask)>>> ma.max(masked_x,axis=1)masked_array(data=[--, --, --], mask=[ True, True, True], fill_value=1e+20, dtype=float64)