Course 1 Week 2 Exercise 5

I have an interesting Dilemma in this problem we are given w as (num_px * num_px * 3, 1) and x as (num_px * num_px * 3, number of examples).

Which is fine when I compute A without transposing w inside sigmoid , however ends up messing with my cost function. I found a work around which is to transpose w and x after multiplication.

However messes with my calculations of dw with a broadcasting issue : alueError: operands could not be broadcast together with shapes (3,2) (1,3)

I’ve tried transposing at the line of dw as well as switching to the use of however I keep getting the same value error. Ive restarted and killed the kernel with no luck.

Any suggestions ?


Your question is related to the forward propagation step. I think the errors you are getting are related to inconsistent matrix dimensions between w and X.

The equations for the step to implement are in the cell just above. If the calculations are implemented correctly, the broadcasting will also work and you will not get error you are seeing.


Hi @jeosol

Yup for forward propagation. Looks like I already passed the exercise above where w and b is defined, though for this exercise w, b, X, Y are defined at the bottom when the function is called. Keep getting stuck with these errors no matter how the data is transposed.

I would skip over the exercise to the others, however the others are dependent on this function

Note that you also have the dimensions of the input images backwards. They are m x 64 x 64 x 3, where m is the number of samples. You then need to “flatten” them into vectors of length 12288. The dimensions end up as 12288 x m. How you implement that step is critical and is explained on this thread.

That having been said, I don’t think that’s really the problem you are encountering in the later cells. I think your problem is that you have somehow gotten stuck on some incorrect ideas. I think you need to first clear your mind a bit. Go for a walk or get something to eat. Then come back and just sit down and read all the instructions in the notebook from the beginning with a “clear mind”. Then hopefully things will become more clear.

If you still have problems after that, please clearly state which section you are working on and then show us that actual output that you are getting from the failed test, including any exception traces.

1 Like