Course 1 wk 2 optional assignment Error

I am writing the code using Atom text editor then running python3 from Terminal. When I tried copy pasting the code exactly from the assignment, I got an error as follows.

File “”, line 18, in sigmoid_derivative
ds = s(1-s)
TypeError: ‘numpy.ndarray’ object is not callable

Dear @eostrom it is not allowed do write results of the assignement directly in the forum, may I ask you to remove the solution? Coming to the error it says TypeError: ‘numpy.ndarray’ object is not callable which means that you are tryng to use a referend to an ndarray and call this as a function (more preciscly a callable). To solve this you need to review the formulation of the sigmod derivative once more which is a quadratic function of s. Hope this helps you.

OK, I removed the solution. I found the error right away after a night of sleep, I just forgot that you need * for multiplication in python. :slight_smile:

@crisrise I am now wondering, can you use the built in np.gradient() to do the same thing? I tried comparing the ds method with the np.gradient() method and got slightly different results. These were the results for each one.
[0.19661193 0.10499359 0.04517666]
[0.1497385 0.11075777 0.07177705]

Dear @eostrom np.gradient calculates a numerical approximation of the derivative which is general and valid for generic differentiable functions. In this specific case it is possible to express the derivative in a closed form expression originated from the original function with some symbolic calculations. Also in this second case, you can calculate a derivative approximation but with a different method. This explain why you see some differences. Happy that you find the issue :+1:

1 Like