python使用反函数还原输入
import numpy as np import matplotlib.pyplot as plt from pynverse import inversefunc def my_tah(x): sigma = -0.1 # base_tah = np.tanh(x) # base_tah = (2/(1+np.exp(-2*x))) - 1 base_tah = (2 / (1 + np.exp(sigma * x))) - 1 result = 5*base_tah return result if __name__ == '__main__': a = np.linspace(-200,200,500) tah_a = my_tah(a) # 自定义的tanh变种函数 tah_inverse = inversefunc(my_tah,tah_a) # 反函数还原 plt.subplot(121) plt.plot(a ,tah_a) plt.subplot(122) plt.plot(a, tah_inverse) # plt.axis('off') plt.show()