numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
clip(a, a_min, a_max, out=None, **kwargs)

Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1.

Equivalent to but faster than np.minimum(a_max, np.maximum(a, a_min)) .

No check is performed to ensure a_min < a_max .

Notes

When :None:None:`a_min` is greater than :None:None:`a_max`, clip returns an array in which all values are equal to :None:None:`a_max`, as shown in the second example.

Parameters

a : array_like

Array containing elements to clip.

a_min, a_max : array_like or None

Minimum and maximum value. If None , clipping is not performed on the corresponding edge. Only one of :None:None:`a_min` and :None:None:`a_max` may be None . Both are broadcast against a.

out : ndarray, optional

The results will be placed in this array. It may be the input array for in-place clipping. :None:None:`out` must be of the right shape to hold the output. Its type is preserved.

**kwargs :

For other keyword-only arguments, see the ufunc docs <ufuncs.kwargs> .

versionadded

Returns

clipped_array : ndarray

An array with the elements of a, but where values < :None:None:`a_min` are replaced with :None:None:`a_min`, and those > :None:None:`a_max` with :None:None:`a_max`.

Clip (limit) the values in an array.

See Also

ufuncs-output-type

ref

Examples

>>> a = np.arange(10)
... a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.clip(a, 1, 8)
array([1, 1, 2, 3, 4, 5, 6, 7, 8, 8])
>>> np.clip(a, 8, 1)
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
>>> np.clip(a, 3, 6, out=a)
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a = np.arange(10)
... a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.clip(a, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8)
array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.clip pandas.core.generic.NDFrame.clip skimage.restoration._denoise.denoise_bilateral skimage.restoration._denoise.denoise_wavelet dask.array.core.Array.clip

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/fromnumeric.py#2083
type: <class 'function'>
Commit: