alwynmathew
(Alwyn Mathew)
1
torch.clamp( input, min, max, out=None)
Clamp all elements in input
into the range [min
, max
] and return a resulting tensor.
Can clamp() assign out-of-range:
value < min
and
value > max
to zero
instead to assigning it to min
and max
respectively?
alwynmathew
(Alwyn Mathew)
2
Possible solution:
zero_tensor = torch.zeros(input.size())
torch.where(input > min, input, zero_tensor)
torch.where(input < max, input, zero_tensor)
where() is only available in 0.4 or higher versions.
You could also do something like
tensor[tensor!=torch.clamp(tensor, min, max)] = 0