This is the error I am getting. I printed the values of w after initiating with zeros
and then after retrieving the parameter(w) by param[‘w’]
Looks like another version of the previous bug with update_parameters
. So how does w go from being 4 x 1 to being 4 x 4? Put your print shapes statements back in and watch what happens.
Dunno if this is a clue, but notice that all the columns are equal. Look across each row and you’ll see that all the values in each row are the same. Hmmmmm.
Debugging is about reasoning from evidence. Start by really looking at what is wrong. Then you have to work backwards to figure out how it got that way. Debugging is not some kind of annoying and distracting side issue: it is a key skill that you need to have to succeed as a programmer. No non-trivial code you ever write is going to work correctly the first time. Your job as a programmer is to make it work.
Here’s another clue: notice that the very first print of w shows it as all zeros, but it is only a 1D array, not a 2D array. How did I know that? From examining the brackets.
I reshaped w into 2d and then it worked.
I wanted to ask if w should always be reshaped into a 2d array
Yes, Prof Ng commented on this somewhere in the lectures in Week 2: we always use 2D arrays here, because we need the notion of “row” and “column” vectors. It is possible to do things with 1D vectors, but when you mix them with 2D matrices, the results can sometimes be a bit surprising. It’s better to just keep everything 2D.
But how did w end up as a 1D array? If you implemented the initialize routine that way, it fails the test cases. Did you not call initialize_with_zeros
from model
? If not, then what was the point of creating that function?