diff options
author | Tyler Reddy <tyler.je.reddy@gmail.com> | 2019-05-15 11:12:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-15 11:12:18 -0700 |
commit | 75ea05fc0af60c685e6c071dae1f04c489a3ce93 (patch) | |
tree | 275abbee3db9582f8bc5df8c970520efc51ecbae /numpy/core/fromnumeric.py | |
parent | 8970dc8e588776bbae45953b2809883c4b6f8ed0 (diff) | |
parent | 31f0bb1dc7611e5401a52103623d15ea4b3dd00f (diff) | |
download | numpy-75ea05fc0af60c685e6c071dae1f04c489a3ce93.tar.gz |
Merge pull request #12519 from eric-wieser/clip-ufunc
ENH/DEP: Use a ufunc under the hood for ndarray.clip
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 7024ac237..58da8a54b 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1961,12 +1961,12 @@ def compress(condition, a, axis=None, out=None): return _wrapfunc(a, 'compress', condition, axis=axis, out=out) -def _clip_dispatcher(a, a_min, a_max, out=None): +def _clip_dispatcher(a, a_min, a_max, out=None, **kwargs): return (a, a_min, a_max) @array_function_dispatch(_clip_dispatcher) -def clip(a, a_min, a_max, out=None): +def clip(a, a_min, a_max, out=None, **kwargs): """ Clip (limit) the values in an array. @@ -1975,6 +1975,9 @@ def clip(a, a_min, a_max, out=None): is specified, values smaller than 0 become 0, and values larger than 1 become 1. + Equivalent to but faster than ``np.maximum(a_min, np.minimum(a, a_max))``. + No check is performed to ensure ``a_min < a_max``. + Parameters ---------- a : array_like @@ -1992,6 +1995,11 @@ def clip(a, a_min, a_max, out=None): The results will be placed in this array. It may be the input array for in-place clipping. `out` must be of the right shape to hold the output. Its type is preserved. + **kwargs + For other keyword-only arguments, see the + :ref:`ufunc docs <ufuncs.kwargs>`. + + .. versionadded:: 1.17.0 Returns ------- @@ -2020,7 +2028,7 @@ def clip(a, a_min, a_max, out=None): array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8]) """ - return _wrapfunc(a, 'clip', a_min, a_max, out=out) + return _wrapfunc(a, 'clip', a_min, a_max, out=out, **kwargs) def _sum_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None, |