fn
clamp
→Tensorclamp(input: Tensor, min: Scalar | None, max: Scalar | None)Element-wise clamping to a closed interval.
Constrains each entry of input to lie within [min, max]. Either bound
may be None to leave that side unbounded.
Parameters
inputTensorInput tensor.
minscalar or NoneLower bound.
None disables the lower clip.maxscalar or NoneUpper bound.
None disables the upper clip.Returns
TensorTensor with the same shape and dtype as input, with values constrained
to [min, max].
Notes
Mathematical definition:
Gradient flows through where the input lies strictly inside the interval and is
zero at the clipped boundaries. Equivalent to clip.
Examples
>>> import lucid
>>> x = lucid.tensor([-3.0, 0.0, 3.0])
>>> lucid.clamp(x, -1.0, 1.0)
Tensor([-1., 0., 1.])