The initialize with zeros

In the following code blocks, I have initialized the w, b with zeros, but when I run the cell, the error appears.

AssertionError Traceback (most recent call last)
2 w, b = initialize_with_zeros(dim)
----> 4 assert type(b) == float
5 print ("w = " + str(w))
6 print ("b = " + str(b))


But in the jupyter notebook, the code has indented.

When running the first cell, there is no error, but in the second the error happened.

Hello @Fei_Xing,

I can’t recall this exercise in the Machine Learning Specialization. What specialization is this assignment for?

The assertion checks whether your b is a float or not and giving it an int will trigger it. 321 is an int, but 321.0 is a float.

Lastly, it is coursera’s honor code to forbid us from sharing assignment, though I am not sure where your exercise is from, I am removing your assignment code just in case.


Yeah. I also have the concern that I have reshaped the code by mistake, but I can’t find the original one now. This assignment is from Week 2 “Logistic Regression with a Neural Network Mindset”, exercise 4.2 - Initializing parameters, Exercise 4 - initialize_with_zeros, if you can please check it for me? Very appropriate.

I suspect it is from the deep learning specialization, I am moving this thread to the DLS category, and please post your future question in the right category.

If you ever need to get the original copy of a notebook, there is a topic about that on the DLS FAQ Thread.

But I think the problem is not indentation here: it is the point that Raymond made. You have to initialize b with a floating point constant, not an integer one. The first step in debugging is understanding what the error message is actually telling you. Then you go from there …

Thanks for you all@rmwkwok@paulinpaloalto. I solved that problem, it’s just like Raymond said, I changed the b type from int to float, and that worked. Thank you all.

1 Like