torch.clamp¶
-
torch.
clamp
(input, min, max, out=None) → Tensor¶ Clamp all elements in
input
into the range [min
,max
] and return a resulting tensor:If
input
is of type FloatTensor or DoubleTensor, argsmin
andmax
must be real numbers, otherwise they should be integers.- Parameters
Example:
>>> a = torch.randn(4) >>> a tensor([-1.7120, 0.1734, -0.0478, -0.0922]) >>> torch.clamp(a, min=-0.5, max=0.5) tensor([-0.5000, 0.1734, -0.0478, -0.0922])
-
torch.
clamp
(input, *, min, out=None) → Tensor
Clamps all elements in
input
to be larger or equalmin
.If
input
is of type FloatTensor or DoubleTensor,value
should be a real number, otherwise it should be an integer.- Parameters
Example:
>>> a = torch.randn(4) >>> a tensor([-0.0299, -2.3184, 2.1593, -0.8883]) >>> torch.clamp(a, min=0.5) tensor([ 0.5000, 0.5000, 2.1593, 0.5000])
-
torch.
clamp
(input, *, max, out=None) → Tensor
Clamps all elements in
input
to be smaller or equalmax
.If
input
is of type FloatTensor or DoubleTensor,value
should be a real number, otherwise it should be an integer.- Parameters
Example:
>>> a = torch.randn(4) >>> a tensor([ 0.7753, -0.4702, -0.4599, 1.1899]) >>> torch.clamp(a, max=0.5) tensor([ 0.5000, -0.4702, -0.4599, 0.5000])