Introduction to Neural Networks and Deep Learning

Dear Community,
Please I have a problem concerning this error and I think it is from the code itself not from my side
[ValidateApp | INFO] Validating ‘/home/jovyan/work/submitted/courseraLearner/W2A2/Logistic_Regression_with_a_Neural_Network_mindset.ipynb’
[ValidateApp | INFO] Executing notebook with kernel: python3
[ValidateApp | ERROR] Timeout waiting for execute reply (30s).
[ValidateApp | ERROR] Interrupting kernel
[ValidateApp | ERROR] Timeout waiting for execute reply (30s).
[ValidateApp | ERROR] Interrupting kernel
Tests failed on 1 cell(s)! These tests could be hidden. Please check your submission.

The following cell failed:

w =  np.array([[1.], [2]])
b = 1.5
X = np.array([[1., -2., -1.], [3., 0.5, -3.2]])
Y = np.array([[1, 1, 0]])
grads, cost = propagate(w, b, X, Y)

assert type(grads["dw"]) == np.ndarray
assert grads["dw"].shape == (2, 1)
assert type(grads["db"]) == np.float64


print ("dw = " + str(grads["dw"]))
print ("db = " + str(grads["db"]))
print ("cost = " + str(cost))

propagate_test(propagate)

The error was:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-14-7cd89fb9dcd2> in <module>
      7 assert type(grads["dw"]) == np.ndarray
      8 assert grads["dw"].shape == (2, 1)
----> 9 assert type(grads["db"]) == np.float64
     10 
     11 

AssertionError: 

and this was my code:

{moderator edit - solution code removed}

The mistake is using keepdims = True on the np.sum call for db. That causes the result to be a numpy array, but you want it to be a scalar.

A couple of other things to note:

You filed this under General Discussion, but I moved it for you to DLS Course 1.

The course Honor Code says that we shouldn’t publicly share source code for the solutions, so the best approach is just to post the output of the test, not the code. I will edit the post to remove the code, so no harm done. Please just keep that in mind for future occurrences.

1 Like