I want to perform min-max normalization on a tensor in PyTorch.
The formula to obtain min-max normalization is
I want to perform min-max normalization on a tensor using some new_min
and new_max
without iterating through all elements of the tensor.
>>>import torch
>>>x = torch.randn(5, 4)
>>>print(x)
tensor([[-0.8785, -1.6898, 2.2129, -0.8375],
[ 1.2927, -1.3187, -0.7087, -2.1143],
[-0.6162, 0.6836, -1.3342, -0.7889],
[-0.2934, -1.2526, -0.3265, 1.1933],
[ 1.2494, -1.2130, 1.5959, 1.4232]])
Is there any way to min-max normalize the given tensor between two values new_min, new_max
?
Suppose I want to scale the tensor from new_min = -0.25
to new_max = 0.25