Exercise 8 of week 2 giving assertion in w

I have my code as

 w,b = initialize_with_zeros(X_train.shape[0])

but i end up with the below error

AssertionError: Wrong values for d['w']. [[ 0.14449502]
 [-0.1429235 ]
 [-0.19867517]
 [ 0.21265053]] != [[ 0.08639757]
 [-0.08231268]
 [-0.11798927]
 [ 0.12866053]]

Need help in fixing this.

The code to which you refer does not have to be “entered” by you. I do not know where you have included it in your notebook, but it is not necessary (nor is it the proper argument). The call to the function (for grading purposes) happens in the test cell below the function and within the “unit-test” function call in the same cell.

That said, the real problem lies within the code you have completed for w = ... in the body of the initialize_with_zeros function (which you are not allowed to post). For starters, take a look at the instructions for Exercise 4.

Hello sir, Im also experiencing the same error although I believe I have initialized w & b correctly:

[Moderator edit – code removed]

And the error:

AssertionError: Wrong values for d[‘w’]. [[ 0.14449502]
[-0.1429235 ]
[-0.19867517]
[ 0.21265053]] != [[ 0.08639757]
[-0.08231268]
[-0.11798927]
[ 0.12866053]]

How would this be solved?

Hi, @Efe_Baydar. The initialize_with_zeros function takes dim as a single argument. The documentation of that function (the “docstring”) clearly states that dim represents the size of vector w.

instead of using dim in the body of your function, you have “hardcoded” a value instead of dim. This defeats the purpose of using functions, which is to have a piece of code that that is reusable in a number of different situations. In other words, you need to allow your initialize_with_zeros function to accept any value of dim that the situation demands. To do that, you need to use dim in the body of your function. Specifically, it should be part of your expression w = ....

Also (and importantly!), posting your code in Discourse or any other public forum is a violation of the Coursera Honor Code. You are encouraged instead to post a snapshot of the complete traceback (i.e. the error log that is sent to the screen). Thanks!