Problem in week 2 section 4.2 - Initializing parameters

Hi
i got an error in a really simple code within the function:
def initialize_with_zeros(dim):
my code is as follow:

YOUR CODE STARTS HERE

w = np.zeros((dim,1))
b = 0

YOUR CODE ENDS HERE

but in the test i see an error as follow:
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))

i also print the type of b in my function as can be seen bellow:
print(type(b))
assert(w.shape == (dim, 1))
assert(isinstance(b, float) or isinstance(b, int))
return w, b

and saw that it is
<class ‘int’>
so i don’t understand what is problem.
since i have started the course again i saw that few week ago the test was written differently
please assist

1 Like

No, this test has not changed at least since April. Well, the assertion is saying that it wants b to have type float, but you’ve shown that yours has type int. So that’s why the assertion “throws”. The point being that the constant 0 is an integer in python. So what would a floating point version of 0 look like? Might it have a decimal point in it, for example? Something to consider. Try running this code and watch what happens:

x = 42
y = 42.
print(f"type(x) = {type(x)}")
print(f"type(y) = {type(y)}")
2 Likes

Thanks for your answer.
Help a lot