|
19 | 19 | 'all', 'amax', 'amin', 'any', 'argmax', |
20 | 20 | 'argmin', 'argpartition', 'argsort', 'around', 'choose', 'clip', |
21 | 21 | 'compress', 'cumprod', 'cumsum', 'cumulative_prod', 'cumulative_sum', |
22 | | - 'diagonal', 'mean', 'max', 'min', 'matrix_transpose', |
| 22 | + 'diagonal', 'mean', 'max', 'min', 'minmax', 'matrix_transpose', |
23 | 23 | 'ndim', 'nonzero', 'partition', 'prod', 'ptp', 'put', |
24 | 24 | 'ravel', 'repeat', 'reshape', 'resize', 'round', |
25 | 25 | 'searchsorted', 'shape', 'size', 'sort', 'squeeze', |
@@ -3279,6 +3279,88 @@ def amin(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue, |
3279 | 3279 | keepdims=keepdims, initial=initial, where=where) |
3280 | 3280 |
|
3281 | 3281 |
|
| 3282 | +def _minmax_dispatcher(a, axis=None, out=None, keepdims=None): |
| 3283 | + return (a,) |
| 3284 | + |
| 3285 | + |
| 3286 | +@array_function_dispatch(_minmax_dispatcher) |
| 3287 | +@set_module('numpy') |
| 3288 | +def minmax(a, axis=None, out=None, keepdims=np._NoValue): |
| 3289 | + """ |
| 3290 | + Return the minimum and maximum of an array or along an axis. |
| 3291 | +
|
| 3292 | + This is functionally equivalent to ``(np.min(a, ...), np.max(a, ...))`` |
| 3293 | + but may be more efficient for large arrays since the intent to compute |
| 3294 | + both is known ahead of time. |
| 3295 | +
|
| 3296 | + Parameters |
| 3297 | + ---------- |
| 3298 | + a : array_like |
| 3299 | + Input data. |
| 3300 | + axis : None or int or tuple of ints, optional |
| 3301 | + Axis or axes along which to operate. By default, flattened input is |
| 3302 | + used. |
| 3303 | +
|
| 3304 | + If this is a tuple of ints, the minimum and maximum are selected |
| 3305 | + over multiple axes, instead of a single axis or all the axes as |
| 3306 | + before. |
| 3307 | + out : tuple of two ndarrays, optional |
| 3308 | + Tuple ``(out_min, out_max)`` of alternative output arrays in which |
| 3309 | + to place the results. They must have the same shape and buffer |
| 3310 | + length as the expected output. |
| 3311 | + keepdims : bool, optional |
| 3312 | + If this is set to True, the axes which are reduced are left |
| 3313 | + in the result as dimensions with size one. With this option, |
| 3314 | + the result will broadcast correctly against the input array. |
| 3315 | +
|
| 3316 | + Returns |
| 3317 | + ------- |
| 3318 | + min : ndarray or scalar |
| 3319 | + Minimum of `a`. If `axis` is None, the result is a scalar value. |
| 3320 | + If `axis` is given, the result is an array of dimension |
| 3321 | + ``a.ndim - 1``. |
| 3322 | + max : ndarray or scalar |
| 3323 | + Maximum of `a`, same shape as `min`. |
| 3324 | +
|
| 3325 | + See Also |
| 3326 | + -------- |
| 3327 | + min : Return the minimum of an array. |
| 3328 | + max : Return the maximum of an array. |
| 3329 | + ptp : Return the range (maximum - minimum) of an array. |
| 3330 | + nanmin : Return the minimum, ignoring NaN values. |
| 3331 | + nanmax : Return the maximum, ignoring NaN values. |
| 3332 | +
|
| 3333 | + Notes |
| 3334 | + ----- |
| 3335 | + NaN values are propagated, that is if at least one item is NaN, the |
| 3336 | + corresponding min and max values will be NaN as well. To ignore NaN |
| 3337 | + values (MATLAB behavior), please use `nanmin` and `nanmax`. |
| 3338 | +
|
| 3339 | + Examples |
| 3340 | + -------- |
| 3341 | + >>> import numpy as np |
| 3342 | + >>> a = np.arange(4).reshape((2, 2)) |
| 3343 | + >>> a |
| 3344 | + array([[0, 1], |
| 3345 | + [2, 3]]) |
| 3346 | + >>> np.minmax(a) |
| 3347 | + (np.int64(0), np.int64(3)) |
| 3348 | + >>> np.minmax(a, axis=0) |
| 3349 | + (array([0, 1]), array([2, 3])) |
| 3350 | + >>> np.minmax(a, axis=1) |
| 3351 | + (array([0, 2]), array([1, 3])) |
| 3352 | +
|
| 3353 | + >>> b = np.arange(5, dtype=np.float64) |
| 3354 | + >>> b[2] = np.nan |
| 3355 | + >>> np.minmax(b) |
| 3356 | + (np.float64(nan), np.float64(nan)) |
| 3357 | + """ |
| 3358 | + kwargs = {} |
| 3359 | + if keepdims is not np._NoValue: |
| 3360 | + kwargs['keepdims'] = keepdims |
| 3361 | + return _methods._minmax(a, axis=axis, out=out, **kwargs) |
| 3362 | + |
| 3363 | + |
3282 | 3364 | def _prod_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None, |
3283 | 3365 | initial=None, where=None): |
3284 | 3366 | return (a, out) |
|
0 commit comments