当前位置:   article > 正文

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

torch.sigmoid

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

1、torch.sigmoid()

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

举例:

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

image-20221020154357858

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

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)
  • 1
  • 2
  • 3

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(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)
  • 1
  • 2
  • 3

image-20221020155402628

3、sum

A = torch.Tensor([[1,2],[3,4],[5,6]])
B = A.sum(dim=0)
print()
  • 1
  • 2
  • 3

([[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)]
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/205880
推荐阅读
相关标签
  

闽ICP备14008679号