W2_A1_size of w changed during vectorization

Due to broadcasting the size of w is changing which is creating problem in further tests of optimization. How to correct it?

That probably means that your “update parameters” logic in optimize is incorrect. Print the shape of w before and after the update and see if it changes. The original w is an argument to optimize, so it starts out being the right shape. So now your job is figure out where the shape became wrong.

BTW it’s not a bug, you don’t need to write out the implementation of sigmoid again in propagate. You’ve already written a function to do that, right? Why not just call it?

Hello @Aryavardhan_Singh_Ra,

It’s crucial for us to read the Error Traceback to give us some hints on how to solve an error.

Let’s read your Error Traceback together. It complains about the shapes of your w and X, and from this part:


We can infer that it is receiving a w that has a shape of (3, 2) and a X that has a shape of (2, 2). Or a np.dot(w.T, X) that has a shape of (3, 2) and a b that has a shape of (2, 2). Then where do the w, X and b come from? The Traceback told us, which is here:

Then we can go back to the notebook and look for that very line, and trace upwards to look for where w,X, and b are actually defined which is here:


They do not have the shapes that the error complained. Also, they are codes provided by the assignment. So here are 2 steps I can suggest to you.

  • Verify that they were not modified in your notebook
  • Run them first, and run the problematic cell again right after, see if the same problem remains


Thanks, I got it. I was not updating b correctly so that was causing problem.

I see. That makes sense. Thanks for letting us know!

1 Like