Week 2 exercise 6, optimize func fails on 3rd iteration

The optimize(w, b, X, Y,…) function fails on the 3rd iteration of the loop with:

<ipython-input-45-3390ca990601> in optimize(w, b, X, Y, num_iterations, learning_rate, print_cost)
     40             ...
---> 42         grads, cost = ...
     43         # YOUR CODE ENDS HERE

<ipython-input-48-b5e684413ba0> in propagate(w, b, X, Y)
---> 37     A = sigmoid(...)
     38     # YOUR CODE ENDS HERE

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

It’s odd because the propagate function already passes the tests so it should just be a matter of passing in the w,b,X,Y vars. When I print the sigmoid( vars ), the vars are the correct shape (wT:(2,2), X:(2,3)) for a dot product but the +b seems to be the wrong shape (2,2). Shouldn’t it also be (2,3)? Is this a test problem?
Actually, if m=3 then I think b.shape = (1,3).

I think it is a test problem with excercise 6 because I use the same sigmoid func in exercise 7 and all tests pass.

Hi Roland_Schuetz,

In case you were not able to resolve this yet: the public tests do not capture all errors, so it is possible that a later test shows a problem in an earlier piece of code. Remember that b is a scalar (a float), not an array, so check your code to see why you get the incorrect shape.

This is not a test problem: the point is that the bug is not in sigmoid. A perfectly correct function can still throw errors if you pass it mismatching arguments. The bug is that you passed a b value to it that has the wrong shape. As Reinoud points out, b should be a scalar, not an array. Either your back prop logic for computing db is wrong or your “update parameters” logic is wrong.