Dls1 - week2 - ex 4

Hello community members! Can someone tell me why I am getting an assertion error at the bottom ? The line which shows error was pre-written in the assignment i.e. I did not add that line

GRADED FUNCTION: initialize_with_zeros

def initialize_with_zeros(dim):

Moderator edit: code removed.

dim = 2
w, b = initialize_with_zeros(dim)

assert type(b) == float
print ("w = " + str(w))
print ("b = " + str(b))

initialize_with_zeros_test(initialize_with_zeros)

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

AssertionError:

The AssertionError indicates that your expression for b is not of the proper Python object type. The assert statement tests that b is of type float (for floating point number). It is most likely that you have initialized it as type int (i.e. integer). Python is picky about the difference. Any integer can be initialized as type float by including a decimal point. For example, x = 2. rather than x = 2. The Python float function also works, i.e. x = float(2), but why waste the keystrokes? :smiley:

1 Like

Ken has pointed out the correct interpretation, but it’s also worth making the “meta” point here:

If a test case fails, you should not assume that the problem is with the test. You should assume that it is your code that is wrong. Then the effort should go into understanding what the test failure message is telling you, as Ken has demonstrated for this particular case. This is the way all the assignments work in this course: the notebook provides “unit test” cells to check that the implementation of each of your functions is correct. Of course it is also the case that just because you pass all the unit tests, that does not mean you will pass the grader. The grader uses different test cases and the unit tests in the notebook do not catch every possible type of error. So logically you can say that passing the unit tests in the notebook is a necessary, but not sufficient condition to pass the grader. :nerd_face:

1 Like

Thanks a lot @kenb for the insight !
Did not waste the keystrokes :slight_smile:

Thanks @paulinpaloalto Paul for the intuition going forward :slight_smile: