import numpy as npimport matplotlib.pyplot as pltfrom scipy import specialx = np.linspace(-100, 100, 1000)y = np.tanh(x) #tanh函数z = special.expit(x) #sigmoid函数plt.figureplt.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()
输出结果: