Coverage for NeuralTSNE/NeuralTSNE/Utils/Preprocessing/Normalizers/normalizers.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-18 16:32 +0000

1import torch 

2 

3 

4def normalize_columns(data: torch.Tensor) -> torch.Tensor: 

5 """Normalize the columns of a 2D `torch.Tensor` to have values in the range `[0, 1]`. 

6 

7 Parameters 

8 ---------- 

9 `data` : `torch.Tensor` 

10 The input 2D tensor with columns to be normalized. 

11 

12 Returns 

13 ------- 

14 `torch.Tensor` 

15 A new tensor with columns normalized to the range `[0, 1]`. 

16 

17 Note 

18 ---- 

19 The normalization is done independently for each column, ensuring that the values in each column are scaled to the range `[0, 1]`. 

20 """ 

21 data_min = data.min(dim=0)[0] 

22 data_range = data.max(dim=0)[0] - data_min 

23 return (data - data_min) / data_range