Below function takes in 2D tensor and normalizes it using broadcasting .The issue is except all values to be in range 0-1 but the result has values outside this range . How to get all values in 2D tensor in range 0-1
def torch_normalize(tensor_list):
means = tensor_list.mean(dim=1, keepdim=True)
stds = tensor_list.std(dim=1, keepdim=True)
normalized_data = (tensor_list - means) / stds
return normalized_data
INPUT
tensor_list=tensor([[-5.6839, -7.5829, -7.2277, -6.5066, -8.4702, -7.9844, -5.6841, 1.8570,
1.6170, -3.7592, -4.4140, -0.4981, 0.2501, 5.8463, 1.8897, -1.3968,
-5.5402, -2.4561, -5.6819]])
Normalized result
tensor([[-0.5981, -1.0615, -0.9748, -0.7988, -1.2780, -1.1594, -0.5981, 1.2420,
1.1835, -0.1284, -0.2882, 0.6673, 0.8499, 2.2155, 1.2500, 0.4480,
-0.5630, 0.1896, -0.5976]])