dpnp.minmax

dpnp.minmax(a, axis=None, out=None, keepdims=False, initial=None, where=True)[source]

Return the minimum and maximum of an array or along an axis.

This is equivalent to (dpnp.min(a, ...), dpnp.max(a, ...)) but computes both the minimum and the maximum in a single pass over a.

For full documentation refer to numpy.minmax.

Parameters:
a{dpnp.ndarray, usm_ndarray}

Input array.

axis{None, 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 integers, the minimum and the maximum are selected over multiple axes, instead of a single axis or all the axes as before.

Default: None.

out{None, tuple of None, dpnp.ndarray or usm_ndarray}, optional

A tuple (min, max) of two arrays in which to place the result. Each array must be of the same shape and buffer length as the expected output. A None entry means that a new array is allocated for that result.

Default: None.

keepdims{None, bool}, 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.

Default: False.

Returns:
outtuple of dpnp.ndarray

A tuple (min, max) holding the minimum and maximum of a. If axis is None, the results are zero-dimensional arrays. If axis is an integer, the results are arrays of dimension a.ndim - 1. If axis is a tuple, the results are arrays of dimension a.ndim - len(axis).

Limitations

Parameters where, and initial are only supported with their default values. Otherwise NotImplementedError exception will be raised.

If an array in out has a data type other than that of a, the result is computed in the data type of a and then cast, while NumPy casts a to the data type of out first. The results differ when the cast does not preserve the order of values, e.g. for a narrowing integer cast.

The arrays in out must not overlap in memory. Interleaved views, such as (r[:, 0], r[:, 1]), are rejected as well, while NumPy accepts them.

See also

dpnp.min

Return the minimum of an array.

dpnp.max

Return the maximum of an array.

dpnp.ptp

Range of values (maximum - minimum) along an axis.

dpnp.nanmin

The minimum value of an array along a given axis, ignores NaNs.

dpnp.nanmax

The maximum value of an array along a given axis, ignores NaNs.

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 dpnp.nanmin and dpnp.nanmax.

Examples

>>> import dpnp 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
(array(0), array(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]))
>>> b = np.arange(5, dtype=float)
>>> b[2] = np.nan
>>> np.minmax(b)
(array(nan), array(nan))