latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.clamp
- tensorplay.functional.clamp(input, min=None, max=None, *, out=None) Tensor[source]
Clamps all elements in
inputinto the range [min,max]. Letting min_value and max_value beminandmax, respectively, this returns:If
minisNone, there is no lower bound. Or, ifmaxisNonethere is no upper bound.Note
If
minis greater thanmaxtensorplay.clamp(..., min, max)sets all elements ininputto the value ofmax.- Parameters:
- Keyword Arguments:
out (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])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

