def initialize_with_zeros(dim):
“”"
This function creates a vector of zeros of shape (dim, 1) for w and initializes b to 0.
Argument:
dim -- size of the w vector we want (or number of parameters in this case)
Returns:
w -- initialized vector of shape (dim, 1)
b -- initialized scalar (corresponds to the bias) of type float
"""
# (≈ 2 lines of code)
# w = ...
# b = ...
# YOUR CODE STARTS HERE
w = np.zeros((dim, 1))
b = 0
# YOUR CODE ENDS HERE
return w, b
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.
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!
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)).