import torch import torch.nn.functional as F x1= torch.Tensor( [ [1,2,3,4],[1,3,4,5],[3,4,5,6]]) y11= F.softmax(x, dim = 0) #对每一列进行softmax y12 = F.softmax(x,dim =1) #对每一行进行softmax x2 = torch.Tensor([1,2,3,4]) y2 = F.softmax(x2,dim=0) 这里的dim=0其实就是张量的0