For fast computations, I have to implement my sigmoid function in Numpy this is the code below
def sigmoid(Z):
"""
Implements the sigmoid activation in bumpy
Arguments:
Z -- numpy array of any shape
Returns:
A -- output of sigmoid(z), same shape as Z
cache -- returns Z, useful during backpropagation
"""
cache=Z
print(type(Z))
print(Z)
A=1/(1+(np.exp((-Z))))
return A, cache
Also some relevant information:
Z=(np.matmul(W,A)+b)
and the type of Z is:
<class 'numpy.ndarray'>
Sadly I am getting a: "bad operand type for unary -: 'tuple' " I have tried to work around this problem without any luck.I appreciate any suggestions. Best
This worked for me. I think no need to use cache because you already initialized it. Try this code below.
import matplotlib.pyplot as plt
import numpy as np
z = np.linspace(-10, 10, 100)
def sigmoid(z):
return 1/(1 + np.exp(-z))
a = sigmoid(z)
plt.plot(z, a)
plt.xlabel("z")
plt.ylabel("sigmoid(z)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With