每天讲解一点PyTorch——3
现在我们学习F.softmax(x, dim = -1),其中import torch.nn.functional as F
dim = -1表明对最后一维求softmax
>>> m
tensor([[0.1000, 0.2000],
[0.3000, 0.4000]])
>>> import torch.nn.functional as F
>>> y = F.softmax(m,dim=0) # 按列F.softmax,列和为1
>>> y
tensor([[0.4502, 0.4502],
[0.5498, 0.5498]])
>>>
>>> y = F.softmax(m,dim=1) #按行F.softmax,行和为1
>>> y
tensor([[0.4750, 0.5250],
[0.4750, 0.5250]])
>>>



