If I have a 3D Tensor (Variable) with size [a,b,c]. consider it as a b*c matrix, and I hope that all these a matrix got row normalized.
To normalize the input tensor we first subtract the mean from the tensor and then the result is divided by the standard deviation. Print the tensor to see how the tensor looks like after normalization.
Row normalization has a name -- ipsative scaling -- which typically involves rescaling a set of features by either dividing by the maximum value for the set or subtracting the mean of the features.
You can use the normalize
function.
import torch.nn.functional as f
f.normalize(input, p=2, dim=2)
The dim=2
argument tells along which dimension to normalize (divide each row vector by its p-norm
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With