Help me ! the code error

week 2 , EXC : 4
What’s wrong ? Although the code is correct and also the rest appear to be wrong as well !1


Hi, Gadah Alharbi.

Welcome to the community.

b should be a float value.

Right! And the error about “np” not being defined just means you have not yet run the earlier cells in the notebook. Try “Cell → Run All Above” first and then run that cell again. Then you’ll get an assertion failure for the error that Rashmi pointed out. :nerd_face:

I did that but what is wrong?

Which error are you currently asking about?

Yes it is, but what is wrong?

Please show us the error message you are getting.

It doesn’t work and I think every line is correct right?

No, your code is incorrect. Rashmi pointed this out already: you have initialized b as an integer value. The assertion fails, because it expects b to be a floating point value. In python, 1 and 1. are not the same thing: the first is an integer, but the second is a floating point value. Do you see the difference?

1 Like

Does it mean that the error is in b = 0 ?

Yes, that is the line that is incorrect.

the correct b = 0.0 ?

Yes, that should work. To understand why, try this:

a = 1
print(f"type(a) = {type(a)}")
b = 1.
print(f"type(b) = {type(b)}")

I did that but it still shows an error Is there a problem with the line ( w ) ?

For the second time, please show us the actual error message (the full exception trace) that you are getting.

Also note the just typing new code doesn’t really do anything until you click “Shift + Enter” to execute the function cell with the changed code. Just calling the function again without that just runs the old code.

this error :
in
1 dim = 2
----> 2 w, b = initialize_with_zeros(dim)
3
4 assert type(b) == float
5 print ("w = " + str(w))

and yes i will that ( Shift + Enter )

That is not the full trace of the error. We can’t actually see the error message.

that :
w = np.zeros(shape=(dim, 1))
^
IndentationError: unexpected indent
and the send me above

That is a python syntax error. Indentation is part of the syntax in python. You can’t just indent however you think looks good. If you are new to python, this course is not set up as an “intro to python”. You might want to check out some python tutorials before you continue.