def sigmoid(x):
s = 1/(1+np.exp(-x))
return s
def sigmoid_derivative(x):
#Arguments: x is A scalar or numpy array
s = sigmoid(x)
ds = s(1-s)
return ds
x = np.array([1, 2, 3])
print ("sigmoid_derivative(x) = " + str(sigmoid_derivative(x)))
I get this error:
TypeError : Traceback (most recent call
last)
<ipython-input-66-2715e4ef84dc> in <module>()
1 x = np.array([1, 2, 3])
----> 2 print ("sigmoid_derivative(x) = " + str(sigmoid_derivative(x)))
<ipython-input-65-177c1f00eabb> in sigmoid_derivative(x)
16 s = sigmoid(x)
---> 17 ds = s(1-s)
TypeError: 'numpy.ndarray' object is not callable
I don't understand where I am going wrong in this. I tried changing it to np.exp() but it still doesn't work. I have been trying to read the documentation and still no clue as to what needs to be done. Can someone give me some pointers?
the problem is s(1-s)
, in python using ()
is to call a function(a callable). for multi, you should put *
there. change your line of code to:
ds = s*(1-s)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.