Rate this Page
★ ★ ★ ★ ★

TensorDictBase.clamp#

TensorDictBase.clamp(min: TensorDictBase | Tensor | float | None = None, max: TensorDictBase | Tensor | float | None = None, *, out=None) → Self#

Clamps all elements in self 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 torch.clamp(..., min, max) sets all elements in input to the value of max.

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.