2026/10/24 7:38:12
手动实现 Softmax 函数
#coding:utf8
import torch
import numpy
softmax的计算
def softmax(x):res []for i in x:res.append(numpy.exp(i))res [r / sum(res) for r in res]return resx [1,2,3,4]
#torch实现的softmax
print(torch.softmax(torch.Tensor(x), 0))
#自己实现的softmax
print(softm…