TensorFlow - 双曲正切函数(tanh)

时间:2022-12-08 19:09:13

TensorFlow - 双曲正切函数(tanh)

flyfish

用python 画一个tanh的图

TensorFlow - 双曲正切函数(tanh)

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-100, 100, 1000)

y = np.tanh(x)

plt.plot(x, y, label = "label", color = "red", linewidth = 2)
plt.xlabel("abscissa")
plt.ylabel("ordinate")
plt.title("tanh Example")
plt.show()

linspace的第一个参数表示起始点,第二个参数表示终止点,第三个参数表示数列的个数。

对比sinh,cosh,tanh

TensorFlow - 双曲正切函数(tanh)

numpy.tanh与下列代码相同
np.sinh(x) / np.cosh(x)
- 1j * np.tan(1j * x).

tanhu=sinhucoshu

双曲正切函数(tanh)与tf.sigmoid非常接近,且与后者具有类似的优缺点。tf.sigmoid和tf.tanh的主要区别在于后者的值域为[-1.0,1.0]。