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 array x 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 with x1 (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 with x1 (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 and max are None, the elements of the returned array must equal the respective elements in x.

  • If a broadcasted element in min is greater than a corresponding broadcasted element in max, behavior is unspecified and thus implementation-dependent.

  • If x and either min or max have different data type kinds (e.g., integer versus floating-point), behavior is unspecified and thus implementation-dependent.

New in version 2023.12.