Your code for b1 and b2 is incorrect. The second dimension should be hard-coded to be 1. The b values are column vectors by definition. You just happen to get lucky that n_y is 1 in that one particular test case, but there are other tests it is invoking from public_tests.py which don’t have n_y as 1.
In other words, just because you pass one test case is not good enough. You need to pass them all and there’s a reason why you don’t. For future reference, you can examine the other test cases by clicking “File → Open” and then opening the file name that I mentioned. Sometimes that is a useful debugging step to understand what values they are using and comparing those between the tests you pass and the ones you don’t.
Well, that’s close, but still not correct. The syntax of np.zeros is that it takes a single “tuple” as the argument, right? So if I want a 3 x 4 array of zeros, I would say this:
A = np.zeros((3,4))
See the difference between that and what you wrote above?
Note that when we invoke np.random.randn, it has different syntax. Why, you ask? The answer is “because”. Seriously. This is the beauty of Open Source Software: it’s free, but you have no guarantee of any conceptual consistency. The two functions were probably implemented by different people at different times with different things in mind. We just have to read the documentation and “deal with it”.
Oh, sorry, I see you actually had that part of the syntax correct in the original code you showed. So that wasn’t the problem: it was just picking the correct dimensions.
Hi,
I am also having issues with the initializing of parameters. I believe my b2 is correct: np.zeros((n_y, 1)), but I get an error that something is wrong with my b2:
Note that the b1 and b2 values agree, but the others do not. Also note that your values for W1 and W2 are all positive, whereas mine are both positive and negative. That probably indicates that you made the most common mistake on this section: using the wrong random function. You probably used “rand” instead of “randn”. Note that they literally wrote out the correct code for you in the instructions: you just have to fill in the dimensions.
The error message is telling you what is wrong: your W1 is the wrong shape. Note that there are two separate test cases: one you can see in the notebook and one that is in the file public_tests.py. Maybe you hard-coded the dimensions to match the test case in the notebook, instead of making the code general by using the actual parameter values that are passed to the function.
Take a look at the test case in public_tests.py and you’ll see that W1 for that test case should be 5 x 3. So put a print statement in your initialize routine that prints the shape of W1:
There is an important lesson to be learned here: it’s always a mistake to “hard-code” things unless they specifically tell you to do that. Our goal is always to write general purpose functions that can be reused with different dimensions. If you’re going to hard-code everything, then what is the point of making it a separate function, right?
Yes of course , I have red this sentence " * Make sure your parameters’ sizes are right. Refer to the neural network figure above if needed." and I write the code according to the network figure
Sorry, I don’t understand. Your code produces the correct answers for the test case that you can see in the notebook.
Oh, well, as long as you pass now and I hope you understand the nature of what you did wrong, then we should just move on. There is plenty more to learn here …