# Maximum recursion depth exceeded

def sigmoid(x):
s=sigmoid(x)
return s

t_x = np.array([1, 2, 3])
print("sigmoid(t_x) = " + str(sigmoid(t_x)))

Why is it showing RecursionError: maximum recursion depth exceeded

Recursion means you are calling the function itself from inside the body of the function. So it is effectively an infinite loop kind of like a cat chasing its own tail. And it never ends until you run out of stack space and it throws that error.

You are writing the sigmoid function here, so you need to implement it, rather than calling back to the function itself. They gave you the mathematical formula and now you need to translate that into numpy python code:

sigmoid(z) = \displaystyle \frac {1}{1 + e^{-z}}

The way to compute e^z in numpy is np.exp(z). And note that function works “elementwise” if z is a numpy array, which is exactly what you want here.

Note: you also filed this thread under General Discussion. You don’t say which specialization and course you are taking, but I’m guessing it is DLS Course 1 Week 2. So I’ll move the thread for you by using the little “edit pencil” on the title line. You’ll have better luck getting your questions answered if you post them under the correct category.