Written and maintained by CASRAI Editorial Board
Last updated
numpy.clip() limits the values in an array to an interval: anything below the lower bound becomes the lower bound, and anything above the upper bound becomes the upper bound. This guide covers the call signature, the one-sided and array-valued forms, the trap that appears when the lower bound exceeds the upper bound, and how np.clip relates to the array method and the pandas equivalent. Checked against the NumPy and pandas documentation on 2026-10-29.
What it is used for in research
In analysis code, clipping caps values at fixed limits. Typical uses are keeping a computed proportion inside [0, 1], limiting a sensor or instrument reading to its valid range, and bounding extreme values before a plot or a downstream calculation. Capping extremes at chosen limits is the same idea behind winsorizing, which replaces values beyond a cut-off with the cut-off itself; see winsorizing vs. trimming for how that choice affects an analysis. np.clip applies limits you supply; it does not choose them from percentiles.
Clipping changes your data. If clipped values feed a reported result, state the bounds you used and how many values were changed, so a reader can reproduce the analysis and judge the effect. Keep the original array if you may need the unclipped values later (see the out parameter below).
Install or access
np.clip is part of NumPy. The official installation page (numpy.org/install) says the only prerequisite is Python itself, and gives these commands:
- pip:
pip install numpy - conda:
conda install numpy, ideally inside an environment created withconda create -n my-envandconda activate my-env
Then import it in your script or notebook: import numpy as np. For background on arrays themselves, see arrays in NumPy.
Step-by-step: clip an array
The signature in the current NumPy documentation is numpy.clip(a, a_min=<no value>, a_max=<no value>, out=None, *, min=<no value>, max=<no value>, **kwargs). The examples below are the ones given in the official reference.
- Create or load the array.
a = np.arange(10)givesarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]). - Clip to an interval.
np.clip(a, 1, 8)returnsarray([1, 1, 2, 3, 4, 5, 6, 7, 8, 8]). Values below 1 became 1 and values above 8 became 8. - Clip one side only.
a_minanda_maxacceptNone; if one isNone, clipping is not performed on that edge. If both areNone, the elements stay the same. For example,np.clip(a, 0, None)sets a floor and no ceiling. - Use array-valued bounds. Both bounds are broadcast against
a, so each element can have its own limit.np.clip(a, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8)returnsarray([3, 4, 2, 3, 4, 5, 6, 7, 8, 8]). - Clip in place if you want to.
np.clip(a, 3, 6, out=a)returnsarray([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])and the originalanow holds those values too.outmay be the input array, must have the right shape to hold the result, and its type is preserved. - Use the array method if you prefer.
a.clip(min, max)is thendarraymethod form; its documentation says one ofmaxorminmust be given and refers tonumpy.clipas the equivalent function.
The min and max keywords (NumPy 2.1.0 and later)
The reference lists min and max as Array API compatible alternatives to a_min and a_max, marked “New in version 2.1.0”. You can pass either the a_min/a_max pair or the min/max pair. If your environment has an older NumPy, use a_min and a_max.
Output and how to read it
The function returns an ndarray with the elements of a, where values less than a_min are replaced with a_min and values greater than a_max are replaced with a_max. Values already inside the interval are untouched, so in the first example 2 through 7 pass through unchanged and only 0 and 9 are altered. Comparing the output to the input element by element, for example counting positions where they differ, tells you how many values were clipped, which is the number to report alongside your bounds.
Troubleshooting
Every value became the same number
The documentation notes that when a_min is greater than a_max, clip returns an array in which all values equal a_max, and that no check is performed to ensure a_min < a_max. Its second example, np.clip(a, 8, 1) on np.arange(10), returns an array of ten 1s. No check is performed on the order of the bounds, so swapped or miscomputed bounds produce a silently constant array. Check that the lower bound is the smaller number before you clip, especially when the bounds are computed from data.
A one-sided limit seems to do nothing
If both a_min and a_max are None, the array comes back unchanged. Make sure at least one bound is a real value.
The original array changed
You passed out=a, which writes the result into the input array. Omit out, or point it at a separate array of the right shape, to keep the original.
Free alternatives
All of these are free, open-source Python tools documented on their own sites. The first three do the same job on different objects.
| Tool | Call | What the documentation says |
|---|---|---|
| NumPy function | numpy.clip(a, a_min, a_max, out=None) |
Returns an ndarray with values limited to the interval; None skips an edge; bounds broadcast against a. |
| NumPy array method | ndarray.clip(min, max, out=None) |
Returns an array whose values are limited to [min, max]; one of max or min must be given. |
| pandas | DataFrame.clip(lower=None, upper=None, *, axis=None, inplace=False) |
Trims values at the input thresholds and returns the same type as the caller; axis is unused for a Series; a missing (NA) threshold does not clip the value. |
| NumPy building blocks | np.minimum(a_max, np.maximum(a, a_min)) |
The documentation describes clip as equivalent to this expression but faster. |
The pandas documentation shows the difference in practice. For a DataFrame with col_0 = [9, -3, 0, -1, 5] and col_1 = [-2, -7, 6, 8, -5], df.clip(-4, 6) gives col_0 = [6, -3, 0, -1, 5] and col_1 = [-2, -4, 6, 6, -4]. Passing lists, as in df.clip([-2, -1], [4, 5]), applies a separate threshold to each column (col_0 becomes [4, -2, 0, -1, 4], col_1 becomes [-1, -1, 5, 5, -1]).
FAQ
What does np.clip do?
It limits the values in an array to an interval. Values below the lower bound become the lower bound and values above the upper bound become the upper bound; values in between are unchanged.
Can I clip only the upper or only the lower end?
Yes. Pass None for the edge you do not want to clip. If both are None, the array is returned with the same elements.
Does np.clip change the original array?
Not by default; it returns a new array. It writes into the input only when you pass the input as out, as in np.clip(a, 3, 6, out=a).
What happens if the minimum is larger than the maximum?
All values in the result equal the maximum, and NumPy does not check the order of the bounds or raise an error.
Is clipping the same as removing outliers?
No. Clipping keeps every observation and replaces extreme values with the bound; removing or trimming drops them. See winsorizing vs. trimming and the resistant measure guide for how each affects summary statistics, and descriptive statistics for how to report them.
How do I clip a pandas DataFrame?
Use DataFrame.clip(lower, upper), which returns the same type as the caller. A missing threshold does not clip the value.
Related guides
Sources
Checked 2026-10-29.
- NumPy reference, numpy.clip: https://numpy.org/doc/stable/reference/generated/numpy.clip.html
- NumPy reference, numpy.ndarray.clip: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.clip.html
- pandas reference, pandas.DataFrame.clip: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.clip.html
- NumPy, Installing NumPy: https://numpy.org/install/








