In numpy, while using np.clamp(x, min, max) we can pass an array of min/max values but pytorch only accepts an integer.
>>> a = np.array([0.4, 10, 0.1])
>>> np.clip(a, [0.3, 0.4,0.5], [0.9, 0.99, 0.999])
array([0.4 , 0.99, 0.5 ])
>>> a = torch.tensor([0.4, 10, 0.1])
>>> torch.clamp(a, [0.3, 0.4,0.5], [0.9, 0.99, 0.999])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: clamp(): argument 'min' (position 2) must be Number, not list
Is there any way I can use torch directly to clamp the values using an array instead of converting the torch.tensor to numpy array and then use np.clip to clip the values and then reconverting them back to torch.tensor?
Or is there any method that would clip the elements of an array to a percentage value? For example, if I pass the value of 10, an element of array with value 100 will be clipped minimum of 90, maximum of 110.