RecursionError: maximum recursion depth exceeded while calling a Python object - Week 2

I get this message, although I already established the sigmoid function as a formula

If you already have defined sigmoid then you should call it sigmoid(x). Why are you placing the sigmoid formula inside as a parameter the sigmoid function? The function itself should have implemented that formula.

I tried doing that but it still shows the “maximum recursion depth exceeded” error

That makes no sense. The error in itself says that you are calling something recursively so many times, python is forced to exit the run because it has hit a limit. Check in your function implememtation of sigmoid what are you calling recursively.

It marks as error one line that was given to me( the first one) and twice the one I wrote

Remove that print line, its wrong. You can just print without str().

It doesnt let me edit that cell, I think because that cell was given to me directly

Hey @Patricio_Ramirez_Tor,
Welcome to the community. As Gent said, you have an issue with your implementation of the sigmoid function. Can you please share your implementation of the same with me?

Make sure to not post the code here since it is strictly against the community guidelines. DM your code to me. For that, click on my name and select Message.


My best guess is s=sigmoid(x) is inside def sigmoid(x):

1 Like

Hi I already sent you a message

Exactly: you can see the bug in the exception trace. You are calling sigmoid from within the sigmoid function. That is called “recursion”. There are some circumstances in which that can be a useful technique, but this is not one of them. :nerd_face: The result is effectively an infinite loop: what will ever terminate the calling? With each additional nested call, you’re going deeper into the stack, so you eventually get a stack overflow as seen above.

1 Like

Failed to see that with the code starts and code end are usually inside the implementation.

Thank you! That helped me fix it, finally it all came down to rewritting it.