Can't understand the assignment at initialising the parameters

Showing NameError while running the code…

Hello Fareed,

Your statement of showing NameError in relation to which context is totally unclear. Please make sure to share a screenshot of your error always when posting your query and also explain briefly your issue. Which week and assignment name need to be mentioned always when posting a query to get any guidance for the issue.

Regards
DP

Hi @Deepti_Prasad

Sure, I am sharing the problem as per your instructions.

I am having problem in the Course Neural Networks and Deep Learning’s Week 2 Programming Assignment: Logistic Regression with a Neural Network Mindset.

In the part 4.2. Initializing parameters, the exercise 4: initialise_with_zeros, I am finding the below mentioned error while running the code. Please, if possible, help me resolve it.

Thank you for your guidance.

Warm Regards,
Fareed Ahmad

Hey @Fareed_A,

I have deleted your code images as it’s against our community guidelines. Please make sure to send a screenshot of the error log only and doesn’t contain any graded code parts.

Cheers!,
Jamal

2 Likes

Jamal thanks for deleting the codes from Fareed’s post. @Fareed_A I told you to only post screenshot of the error.

Jamal can you edit and keep the second image which has its error log.

Thank you

Regards
DP

1 Like

Done

hello Fareed,

I have deleted my comment as my reasoning for this thread for error output was incorrect.

Please follow the other mentor’s comment for the correct reasoning for the issue thread.

Also thank you posting it with details this time. Kindly follow same pointer in future when you have any issue, or query while posting a new topic.

Regards
DP

Hey @Jamal022 @Deepti_Prasad I am sorry for my mistakes but we all learn from mistakes and grow together. Next time, I’ll keep the important things you’ve both told me in mind and post accordingly.

Thank you @Jamal022 and @Deepti_Prasad for helping me out!
stay blessed! :slight_smile:

Warm Regards,
Fareed Ahmad

I hope your issue is resolved. select the appropriate comment and close the thread, or explain how you resolved your issue

Regards
DP

That is not the reason for the “np: name not found” error. If you specified a non-recognized key word in a numpy function the error you would get is completely different and it would be clear that the keyword was not recognized. It was not necessary to specify the dtype, but it is not the cause of the error. That error just means you have not run the earlier “import” cell in the notebook that is where np is defined. Every time you open the notebook you have to run all the cells in order so that everything is defined. Please do “Cell → Run All Above” and then rerun your initialize function test.

Here is a demonstration of how the dtype argument works with numpy zeros:

A = np.zeros((3,4), dtype=np.float32)
print(f"type(A) {type(A)}")
print(f"A.dtype {A.dtype}")
print(f"A {A}")
A = np.zeros((3,4), dtype=np.int16)
print(f"type(A) {type(A)}")
print(f"A.dtype {A.dtype}")
print(f"A {A}")

Running the above gives this output:

type(A) <class 'numpy.ndarray'>
A.dtype float32
A [[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]
type(A) <class 'numpy.ndarray'>
A.dtype int16
A [[0 0 0 0]
 [0 0 0 0]
 [0 0 0 0]]

So you can see that the data type of the individual elements is controlled by the dtype argument. It is not necessary to specify here, because the default is np.float64, which works fine for our purposes. But specifying it does no harm and is not the cause of the issue here.

Now here is what happens if you specify an unknown keyword argument:

A = np.zeros((3,4), dtyp=np.int16)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-632348a97362> in <module>
      7 print(f"A.dtype {A.dtype}")
      8 print(f"A {A}")
----> 9 A = np.zeros((3,4), dtyp=np.int16)

TypeError: 'dtyp' is an invalid keyword argument for zeros()