Course Name: Neural Network and Deep Learning _Coursera Course by Andrew Ng
Week 03, Programming Assignment; Excersize 3: Initialize Parameter

please see the code and error. Can you please tell me the whats wrong?

{moderator edit - solution code removed}

While defining the parameters, like W, you are using explicit values, like (4, 2). Have you tried using instead the parameters passed to the function, namely n_x , n_h, and n_y?

IMPORTANT: Please delete your code - publishing code is against the code of conduct of the community. Thank you!

Well, it works now. Thank you for the solution.

Great! I am glad it worked now.

@Juan_Olano , In the same course programming assignment; For Exercise 5 - compute_cost; I got the following error:

Do you know why?

Hello Sumon Majumdar,

Did you follow the instructions of using np.multiply followed by np.sum? Using this process, will give you a float value.

1 Like

I suspect that you have implemented the formulas suggested in the instructions. There’s actually a bit more to it.

Remember the cost formula for logistic regression from week 2? check it out and try with that.

@Rashmi , Hi…Yes…I used this exactly same way given in instructions.

Exactly - that’s not the one you want to use. See the formula given at the beginning of the section 4 (formula 13).

@Juan_Olano @Rashmi , thank you for your reply. It works now. What I did, was I just used one part of the cost formula because only one part is given in the instructions code.

I am glad it worked. Now, the instructions are not given with the entire solution but with parts or hints… but the instructions at the top are clearly showing the formula that needs to be implemented :slight_smile:

I am very happy that it works now!



@Juan_Olano Well…I am stuck again in Excercise 8 [. Exercise 8 - nn_model]

do you know what should the code for parameters? I used…np.random.randn( )

See @Rashmi 's post above. It seems you are not getting a float but a tuple. Rashmi provides hints as to what to do. Please try that and let us know.

@Juan_Olano Hi, Rashmi’s hint was for Excercise 5. But I am now working on Exercise 8. Here, it is asked to initialize parameters. Which should be a one-line code.

Can you please explain a bit?

Ah! you are right … so here the key is to pass the appropriate parameters to the function that inits the parameters. If you scroll up to the definition of the function that inits the params, you’ll be able to verify the signature needed on this function, that is, the parameters that you need to pass. I think that if you nail this down, you’ll be good to go, unless there’s any other issue in the ‘for’ loop below. Try that and let me know.

… and let me move ahead of the game here. In the for-loop, the instructions will indicate that you’ll have to call the functions you’ve already developed above, in the order and with the params indicated with the instructions. So just be careful in selecting the appropriate function on each step, and passing to them the right params, for which you can always scroll up and review the params needed by each one of these functions.

Hope this helps!

@Juan_Olano hi, thank you for yoour reply. But still, I can not find out the solution. I tried in many ways…

Please send me the code you’ve tried via Direct Message and I’ll try to provide a more focused hint.

@Sumon_Mojumder , I think you are not using the appropriate function to initialize the parameters.

Do this: Go to the top of the lab and in a piece of paper write down all the functions that you have in this lab. The first ones would be:


When you have all these functions in the list, see in your exercise 8 which ones are needed at each step of the exercise.

Let me know how this goes.


# Initialize parameters
#(≈ 1 line of code)
# parameters = ...
parameters =...


It says “initialize parameters”. Is there a function that can do this for you?