clip¶
- clip(x: array, /, min: int | float | array | None = None, max: int | float | array | None = None) array¶
Clamps each element
x_iof the input arrayxto the range[min, max].- Parameters:
x (array) – input array. Should have a real-valued data type.
min (Optional[Union[int, float, array]]) – lower-bound of the range to which to clamp. If
None, no lower bound must be applied. Must be compatible withxandmax(see Broadcasting). Should have a real-valued data type. Default:None.max (Optional[Union[int, float, array]]) – upper-bound of the range to which to clamp. If
None, no upper bound must be applied. Must be compatible withxandmin(see Broadcasting). Should have a real-valued data type. Default:None.
- Returns:
out (array) – an array containing element-wise results. The returned array must have the same data type as
x.
Notes
If both
minandmaxareNone, the elements of the returned array must equal the respective elements inx.If a broadcasted element in
minis greater than a corresponding broadcasted element inmax, behavior is unspecified and thus implementation-dependent.If
xhas an integral data type and a broadcasted element inminormaxis outside the bounds of the data type ofx, behavior is unspecified and thus implementation-dependent.If
xand eitherminormaxhave different data type kinds (e.g., integer versus floating-point), behavior is unspecified and thus implementation-dependent.For scalar
minand/ormax, the scalar values should follow type promotion rules for operations involving arrays and scalar operands (see Type Promotion Rules).
Special cases
If
x_iisNaN, the result isNaN.If
min_iisNaN, the result isNaN.If
max_iisNaN, the result isNaN.
New in version 2023.12.