Skip to content

Instantly share code, notes, and snippets.

@Priyansh-Kedia
Created May 19, 2021 10:03
Show Gist options
  • Save Priyansh-Kedia/07f501da18bfd64543c513e137bb7e1a to your computer and use it in GitHub Desktop.
Save Priyansh-Kedia/07f501da18bfd64543c513e137bb7e1a to your computer and use it in GitHub Desktop.
Plot the sigmoid function along with its derivative
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def derivative(x, step):
return (sigmoid(x+step) - sigmoid(x)) / step
x = np.linspace(-10, 10, 1000)
y1 = sigmoid(x)
y2 = derivative(x, 0.0000000000001)
plt.plot(x, y1, label='sigmoid')
plt.plot(x, y2, label='derivative')
plt.legend(loc='upper left')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment