简体   繁体   中英

Getting error (numpy.ndarray not callable) in Finding derivative of Sigmoid function

I am new to neutral network & was trying to find derivative of sigmoid function.please help me to fix this error. My code is like;

import numpy as np

def sigmoid_derivative(x):

a=1/np.exp(x) +1

s=1/a

ds=s(1-s) 

return ds  

x = np.array([1, 2, 3])

print ("sigmoid_derivative(x) = " + str(sigmoid_derivative(x)))

Output:Error, numpy.ndarray is not callable.

on line ds=s(1-s) you are calling numpy.ndarray s with parameter 1-s, I think you need ds=s * (1-s)

You're missing a multiplication operator:

ds= s * (1-s) 

First of all, you got the sigmoid function wrong.

What I suggest is something like:

def sigmoid(x):
    return 1.0 / (1.0 + np.exp(-x))


def sigmoid_derivative(x):
    return sigmoid(x) * (1 - sigmoid(x))

Here's a link that would help you understand better: Derivative of the Sigmoid function

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM