numpy.minmax#
- numpy.minmax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)[source]#
Return the minimum and maximum of an array or along an axis.
This is equivalent to
(np.min(a, ...), np.max(a, ...))but computes both the minimum and the maximum in a single pass over a.- Parameters:
- aarray_like
Input data.
- 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 reduction is performed over multiple axes, instead of a single axis or all the axes as before.
- outtuple of ndarray, optional
A tuple
(min, max)of two arrays in which to place the result. Must be of the same shape and buffer length as the expected output. See Output type determination for more details.- 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 or tuple of scalars, optional
If a tuple, the first entry is the maximum value for the minimum result and the second entry is the minimum value for the maximum result. If a scalar, the same value is used for both. Also used as a fill value for empty slices. See
reducefor details.- wherearray_like of bool, optional
Elements to compare for the minimum and maximum. See
reducefor details.
- Returns:
- resulttuple of ndarray or scalar
A tuple
(min, max)holding the minimum and maximum of a. If axis is None, the results are scalar values. If axis is an int, the results are arrays of dimensiona.ndim - 1. If axis is a tuple, the results are arrays of dimensiona.ndim - len(axis).
See also
Notes
NaN values are propagated, that is if at least one item is NaN, the corresponding output value will be NaN as well. To ignore NaN values use
nanminandnanmax.Examples
>>> import numpy as np >>> a = np.arange(4).reshape((2, 2)) >>> a array([[0, 1], [2, 3]]) >>> np.minmax(a) # min and max of the flattened array (np.int64(0), np.int64(3)) >>> np.minmax(a, axis=0) # along the first axis (array([0, 1]), array([2, 3])) >>> np.minmax(a, axis=1) # along the second axis (array([0, 2]), array([1, 3]))