python Tanh函数如何理解

730次阅读
没有评论

python

说明

1、Tanh是双曲函数中的一个,Tanh()为双曲正切。

在数学中,双曲正切Tanh是由基本双曲函数双曲正弦和双曲余弦推导而来。

2、优点,比Sigmoid函数收敛速度更快、输出以0为中心。缺点,由于饱和性产生的梯度消失。

实例

import numpy as np
import matplotlib.pyplot as plt
from scipy import special
x = np.linspace(-100, 100, 1000)
 
y = np.tanh(x)         #tanh函数
z = special.expit(x)   #sigmoid函数
 
plt.figure
plt.plot(x, y, color = "red", linewidth = 2, label="tanh")
plt.plot(x, z, color = "b", linewidth = 2, label="sigmoid")
plt.xlabel("abscissa")
plt.ylabel("ordinate")
plt.legend(loc='upper left')
plt.title("tanh&sigmoid Example")
plt.show()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-08-02发表,共计526字。
新手QQ群:570568346,欢迎进群讨论 Python51学习