- 函数作用
对输入的数据(tensor)进行指定维度的L2_norm运算。
- 代码示例
import torch.nn.functional as F
>>> a=torch.tensor([1,2,3,4],dtype=torch.float32)
>>> a
tensor([1., 2., 3., 4.])
>>> F.normalize(a,p=2,dim=0) #对指定维度进行运算
tensor([0.1826, 0.3651, 0.5477, 0.7303])
对输入的数据(tensor)进行指定维度的L2_norm运算。
import torch.nn.functional as F
>>> a=torch.tensor([1,2,3,4],dtype=torch.float32)
>>> a
tensor([1., 2., 3., 4.])
>>> F.normalize(a,p=2,dim=0) #对指定维度进行运算
tensor([0.1826, 0.3651, 0.5477, 0.7303])