clip

dragon.math.clip(
  inputs,
  low=None,
  high=None,
  **kwargs
)[source]

Compute the clipped input according to the given bounds.

\[\text{out} = \min(\max(\text{input}, \text{low}), \text{high}) \]

Examples:

x = dragon.constant([0, 1, 2, 3])
print(dragon.math.clip(x, low=1))  # [1, 1, 2, 3]
print(dragon.math.clip(x, high=2))  # [0, 1, 2, 2]
print(dragon.math.clip(x, low=1, high=2))  # [1, 1, 2, 2]
Parameters:
  • inputs (dragon.Tensor) The input tensor.
  • low (number, optional) The value to \(\text{low}\).
  • high (number, optional) The value to \(\text{high}\).
Returns:

dragon.Tensor The output tensor.