World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Kajal Pawar
2 years ago
def tanh_function(z):
return (np.exp(z) - np.exp(-z)) / (np.exp(z) + np.exp(-z))
def tanh_prime_function(z):
return 1 - np.power(tanh_function(z),2)
# import libraries
import matplotlib.pyplot as plt
import numpy as np
#creating a tanh function
def tanh(x):
a=(np.exp(x)-np.exp(-x))/(np.exp(x)+np.exp(-x))
dt=1-t**2
return a,da
b=np.arange(-4,4,0.01)
tanh(b)[0].size,tanh(b)[1].size
# Setup centered axes
fig, ax = plt.subplots(figsize=(9, 5))
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
# Create and show plot
ax.plot(b,tanh(b)[0], color="#307EC7", linewidth=3, label="tanh")
ax.plot(b,tanh(b)[1], color="#9621E2", linewidth=3, label="derivative")
ax.legend(loc="upper right", frameon=false)
fig.show()