Week 2 Exercise 6 - Propagate passes all tests but raises errors in Optimize

Hi, can anyone help with the below issue? I’ve checked over and over and the function pointed out is correct as far as I can tell. Lab ID: woyrvzzs

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-33-3483159b4470> in <module>
----> 1 params, grads, costs = optimize(w, b, X, Y, num_iterations=100, learning_rate=0.009, print_cost=False)
      2 
      3 print ("w = " + str(params["w"]))
      4 print ("b = " + str(params["b"]))
      5 print ("dw = " + str(grads["dw"]))

<ipython-input-32-8fc337d76e13> in optimize(w, b, X, Y, num_iterations, learning_rate, print_cost)
     35         # grads, cost = ...
     36         # YOUR CODE STARTS HERE
---> 37         grads, cost = propagate(w, b, X, Y)
     38 
     39         # YOUR CODE ENDS HERE

<ipython-input-30-1b890191f0dd> in propagate(w, b, X, Y)
     30     # cost = ...
     31     # YOUR CODE STARTS HERE
---> 32     A = sigmoid(np.dot(w.T, X) +b)
     33     cost =  np.sum(Y * np.log(A) + (1 - Y) * np.log(1 - A)) /-m
     34 

ValueError: operands could not be broadcast together with shapes (2,3) (2,2) 

Disregard. I fixed it.

Great! Yes, it is a general principle of debugging that just because the error is thrown in a particular function, it does not mean that is where the actual bug is. propagate does not change the dimensions of anything, so the reason you got that exception there is that you passed in objects that were already the wrong shape. The bug was in optimize I bet. :nerd_face:

It turns out I had made a typo when changing the value of b in my propagate function.

w = w - learning_rate*dw
b = w - learning_rate*dw
1 Like