numpy has three different functions which seem like they can be used for the same things --- except that numpy.maximum can only be used element-wise, w
For completeness, in Numpy there are four maximum related functions. They fall into two different categories:
np.amax/np.max, np.nanmax: for single array order statisticsnp.maximum, np.fmax: for element-wise comparison of two arraysNaNs propagator np.amax/np.max and its NaN ignorant counterpart np.nanmax.
np.max is just an alias of np.amax, so they are considered as one function.
>>> np.max.__name__
'amax'
>>> np.max is np.amax
True
np.max propagates NaNs while np.nanmax ignores NaNs.
>>> np.max([np.nan, 3.14, -1])
nan
>>> np.nanmax([np.nan, 3.14, -1])
3.14
NaNs propagator np.maximum and its NaNs ignorant counterpart np.fmax.
Both functions require two arrays as the first two positional args to compare with.
# x1 and x2 must be the same shape or can be broadcast
np.maximum(x1, x2, /, ...);
np.fmax(x1, x2, /, ...)
np.maximum propagates NaNs while np.fmax ignores NaNs.
>>> np.maximum([np.nan, 3.14, 0], [np.NINF, np.nan, 2.72])
array([ nan, nan, 2.72])
>>> np.fmax([np.nan, 3.14, 0], [np.NINF, np.nan, 2.72])
array([-inf, 3.14, 2.72])
The element-wise functions are np.ufunc(Universal Function), which means they have some special properties that normal Numpy function don't have.
>>> type(np.maximum)
>>> type(np.fmax)
>>> #---------------#
>>> type(np.max)
>>> type(np.nanmax)
And finally, the same rules apply to the four minimum related functions:
np.amin/np.min, np.nanmin; np.minimum, np.fmin.