Week 2 program test

Hello! I can’t find the mistake in this code:

GRADED FUNCTION: initialize_with_zeros

def initialize_with_zeros(dim):
This function creates a vector of zeros of shape (dim, 1) for w and initializes b to 0.

dim -- size of the w vector we want (or number of parameters in this case)

w -- initialized vector of shape (dim, 1)
b -- initialized scalar (corresponds to the bias) of type float

# (≈ 2 lines of code)
# w = ...
# b = ...
w = np.zeros((dim, 1))
b = 0

return w, b

It might be in w, but I don’t understand. Please help!

Hi @AnnaPetrov, and welcome to the Specialization. The NameError generated means that the very first cell of the notebook, comprised of a bunch of import statements, has not been run prior to the execution of the cell containing the initialize_with_zeros() function. In this particular case, the interpreter is complaining that it can not find np in the relevant “namespace” because the statement import numpy as np has not been executed.

1 Like

Thank you for the answer! Now the next step works, but in this part I still have some mistake

Hello again, Anna. The assert statement in the testing code block has thrown an “exception” (i.e. an error message) indicating that the parameter b is of the wrong Python type. The Python type function returns the object type. In this case, it was looking for type float (a floating point number). You instead assigned an integer to b. The easiest way to handle this is to put a period (decimal point) after the integer. That is, b = 0.

Since you are a first time poster, I will remind you that we do not allow learner’s to post their code from the function. Instead, please limit yourself to the Traceback. Thanks! :smiley:

1 Like

Thank you very much again! Now I have no mistakes and sorry I won’t post my code again.

You are wlecome! Anytime you want to verify the type fo an object, you can insert a print(type(object_name)) statement into your function. E.g. print(type(b)).