torch.sigmoid()、torch.softmax()、sum
1、torch.sigmoid()
举例:
A = torch.Tensor([1,2,3]) #一维
B = torch.sigmoid(A)
print(B)
A = torch.Tensor([[1,2,3],[1,2,3]]) #二维
B = torch.sigmoid(A)
print(B)
2、torch.softmax()
二维情况下,dim=1时,对行进行计算
A = torch.Tensor([[1,1],[1,1],[1,3]])
B = torch.softmax(A,dim=1) #对行 进行softmax
print(B)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GIDLbimg-1666254112726)(https://cdn.jsdelivr.net/gh/bean661/images@main/img/202210201552330.png)]
二维情况下,dim=0时,对列进行计算
A = torch.Tensor([[1,1],[1,1],[1,3]])
B = torch.softmax(A,dim=0) #对列 进行softmax
print(B)
3、sum
A = torch.Tensor([[1,2],[3,4],[5,6]])
B = A.sum(dim=0)
print()
([[1,2],[3,4],[5,6]])
B = A.sum(dim=0)
print()
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LPNL8qgZ-1666254112727)(https://cdn.jsdelivr.net/gh/bean661/images@main/img/202210201620452.png)]