fn
clip
→Tensorclip(input: Tensor, min: Scalar | None, max: Scalar | None)Element-wise clamping to a closed interval.
Clips each entry of input so that it lies within [min, max]. Either bound
may be None to leave that side unbounded. Alias of clamp.
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 min < x < max; at the clipped boundaries it is
treated as zero. If min > max the result is implementation-defined.
Examples
>>> import lucid
>>> x = lucid.tensor([-2.0, -0.5, 0.5, 2.0])
>>> lucid.clip(x, -1.0, 1.0)
Tensor([-1., -0.5, 0.5, 1.])