Error with torch.nn.functional.normalize

Hi,
when I try to normalize the input for my neural net, I receive the error:
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

For the following code:

input = torch.tensor(data=[1000, 4, 0.1, 0], dtype=torch.float32)

input_norm = torch.nn.functional.normalize(input)

I cannot really make sense out of it, what is my mistake here?

Thanks in advance!

functional.normalize expect input dimention greater than 1.
maybe this fixes your issue.

input = torch.tensor(data=[[1000, 4, 0.1, 0]], dtype=torch.float32)

input_norm = torch.nn.functional.normalize(input)
1 Like

Thanks, that worked!
The best way to “transform” it best would be to do this?

input_norm.data = input_norm.data[0]

1 Like