larray.LArray.clip

LArray.clip(self, minval=None, maxval=None, out=None)[source]

Clip (limit) the values in an array.

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

Parameters
minvalscalar or array-like, optional

Minimum value. If None, clipping is not performed on lower bound. Defaults to None.

maxvalscalar or array-like, optional

Maximum value. If None, clipping is not performed on upper bound. Defaults to None.

outLArray, optional

The results will be placed in this array.

Returns
LArray

An array with the elements of the current array, but where values < minval are replaced with minval, and those > maxval with maxval.

Notes

  • At least either minval or maxval must be defined.

  • If minval and/or maxval are array_like, broadcast will occur between self, minval and maxval.

Examples

>>> arr = ndtest((3, 3)) - 3
>>> arr
a\b  b0  b1  b2
 a0  -3  -2  -1
 a1   0   1   2
 a2   3   4   5
>>> arr.clip(0, 2)
a\b  b0  b1  b2
 a0   0   0   0
 a1   0   1   2
 a2   2   2   2

Clipping on lower bound only

>>> arr.clip(0)
a\b  b0  b1  b2
 a0   0   0   0
 a1   0   1   2
 a2   3   4   5

Clipping on upper bound only

>>> arr.clip(maxval=2)
a\b  b0  b1  b2
 a0  -3  -2  -1
 a1   0   1   2
 a2   2   2   2