cf.Data.clip¶
-
Data.
clip
(a_min, a_max, units=None, inplace=False, i=False)[source]¶ Clip (limit) the values in the data array in place.
Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of [0, 1] is specified then values smaller than 0 become 0 and values larger than 1 become 1.
- Parameters
- a_min: number
Minimum value. If
None
, clipping is not performed on lower interval edge. Not more than one ofa_min
anda_max
may beNone
.- a_max: number
Maximum value. If
None
, clipping is not performed on upper interval edge. Not more than one ofa_min
anda_max
may beNone
.- units:
str
orUnits
Specify the units of a_min and a_max. By default the same units as the data are assumed.
- inplace:
bool
, optional If True then do the operation in-place and return
None
.- i: deprecated at version 3.0.0
Use the inplace parameter instead.
- Returns
Examples
>>> d = cf.Data(np.arange(12).reshape(3, 4), 'm') >>> print(d.array) [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] >>> print(d.clip(2, 10).array) [[ 2 2 2 3] [ 4 5 6 7] [ 8 9 10 10]] >>> print(d.clip(0.003, 0.009, 'km').array) [[3. 3. 3. 3.] [4. 5. 6. 7.] [8. 9. 9. 9.]]