Skip to content

Instantly share code, notes, and snippets.

@f0nzie
Last active March 10, 2023 23:15
Show Gist options
  • Save f0nzie/e5e711b63445019eb3e624ce5fa25fe9 to your computer and use it in GitHub Desktop.
Save f0nzie/e5e711b63445019eb3e624ce5fa25fe9 to your computer and use it in GitHub Desktop.
Compute the gradient (also called the slope or derivative) of the sigmoid function with respect to its input x. You can store the output of the sigmoid function into variables and then use it to calculate the gradient.
def sigmoid_derivative(x):
"""
Compute the gradient (also called the slope or derivative) of the sigmoid function with respect to its input x.
You can store the output of the sigmoid function into variables and then use it to calculate the gradient.
Arguments:
x -- A scalar or numpy array
Return:
ds -- Your computed gradient.
"""
s = 1 / (1 + np.exp(-x))
ds = s * (1 - s)
return ds
@KianYang-Lee
Copy link

Good thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment