Normalize 3D Tensor


Is there any way to min-max (actually, value / max-value) normalize a 3D Tensor by two dimensions?
Let’s say we have 10x20x30 and I want to normalize it regarding the last two dimensions.
I expect to have a matrix 20x30 such that each position on that matrix is the max value in the first dimension of the original tensor.
This way, by doing 10x20x30 (normalized) * 20x30 = 10x20x30 (original).

Sorry for the silly question, but I’m struggling with it for a while.

Hello gsouza7,

You need to take the maximum along the first dimension, like so:

x = torch.randn(10, 20, 30)
x_max = x.max(dim=0).values
x_normalized = x / x_max
1 Like