【PyTorch】教程:torch.nn.Tanh

torch.nn.Tanh

原型

CLASS torch.nn.Tanh()

定义

Tanh ( x ) = t a n h ( x ) = exp ⁡ ( x ) − exp ⁡ ( − x ) exp ⁡ ( x ) + exp ⁡ ( − x ) \text{Tanh}(x)=tanh(x)=\frac{\exp(x)-\exp(-x)}{\exp(x)+\exp(-x)} Tanh(x)=tanh(x)=exp(x)+exp(x)exp(x)exp(x)

在这里插入图片描述

代码

import torch
import torch.nn as nn

m = nn.Tanh()
input = torch.randn(4)
output = m(input)

print("input: ", input)
print("output: ", output)

# input:  tensor([ 0.1298, -0.4605,  0.2767, -0.9252])
# output:  tensor([ 0.1291, -0.4305,  0.2699, -0.7283])

【参考】

Tanh — PyTorch 1.13 documentation

猜你喜欢

转载自blog.csdn.net/zhoujinwang/article/details/129642080