clip¶
- clip(x: array, /, min: int | float | array | None = None, max: int | float | array | None = None) array ¶
Clamps each element
x_i
of the input arrayx
to 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 withx1
(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 withx1
(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
min
andmax
areNone
, the elements of the returned array must equal the respective elements inx
.If a broadcasted element in
min
is greater than a corresponding broadcasted element inmax
, behavior is unspecified and thus implementation-dependent.If
x
and eithermin
ormax
have different data type kinds (e.g., integer versus floating-point), behavior is unspecified and thus implementation-dependent.
New in version 2023.12.