torch.sigmoid()、torch.softmax()、sum

torch.sigmoid()、torch.softmax()、sum

1、torch.sigmoid()

对每个元素进行处理(函数为image-20221020154509016)

举例:

A = torch.Tensor([1,2,3]) #一维
B = torch.sigmoid(A)
print(B)

image-20221020154357858

A = torch.Tensor([[1,2,3],[1,2,3]]) #二维
B = torch.sigmoid(A)
print(B)

image-20221020154650404

2、torch.softmax()

公式:image-20221020155037989

二维情况下,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)

image-20221020155402628

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)]

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2023年9月17日
下一篇 2023年9月17日

相关推荐