# tensorplay.functional.clamp Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.clamp.html ```python tensorplay.functional.clamp(input, min=None, max=None, *, out=None) → Tensor ``` Clamps all elements in input into the range [ min, max ]. Letting min_value and max_value be min and max, respectively, this returns: $$y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)$$ If min is None, there is no lower bound. Or, if max is None there is no upper bound. > **Note** > > If min is greater than max tensorplay.clamp(..., min, max) sets all elements in input to the value of max. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - min (Number or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – lower-bound of the range to be clamped to - max (Number or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – upper-bound of the range to be clamped to Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> a = tensorplay.randn(4) >>> a tensor([-1.7120, 0.1734, -0.0478, -0.0922]) >>> tensorplay.clamp(a, min=-0.5, max=0.5) tensor([-0.5000, 0.1734, -0.0478, -0.0922]) >>> min = tensorplay.linspace(-1, 1, steps=4) >>> tensorplay.clamp(a, min=min) tensor([-1.0000, 0.1734, 0.3333, 1.0000]) ```