import torch.nn as nn
torch.nn.Sigmoid()
一、sigmoid介绍
sigmoid是激活函数的一种,它会将样本值映射到0到1之间。
sigmoid的公式如下:
二、sigmoid的应用
代码:
import torch.nn as nn
import torch
#取一组满足标准正态分布的随机数构成3*3的张量
t1 = torch.randn(3,3)
m = nn.Sigmoid()
t2 = m(t1)
print(t1)
print(t2)
运行结果:
tensor([[ 0.1904, 0.5954, 1.8083],
[ 1.5643, -0.2557, 1.8694],
[ 0.0155, -2.0995, -1.3233]])
tensor([[0.5475, 0.6446, 0.8592],
[0.8270, 0.4364, 0.8664],
[0.5039, 0.1091, 0.2103]])
标签:nn,sigmoid,torch,t1,Sigmoid,import
From: https://www.cnblogs.com/chaofengya/p/17126299.html