Exercise 8 - Week 2

Hello. I am not sure why I am getting the error:
‘operands could not be broadcast together with shapes (4,3) (1,7)’

Here is my code for the model:

{moderator edit - solution code removed}

Any assistance is greatly appreciated. I looked through the other topics, not seeing where I can pull a solution.

Where is that error actually getting thrown? Is it in predict? If so, then the first question is what is the value of w that you are passing to predict? Where did it come from? One key thing to realize is that calling optimize does not directly modify the w and b values at the local scope of the model function, right? You need to retrieve them from the returned values of the optimize function. The code you show

params = {“w”: w,
“b”: b}

does not retrieve the values. It stores them in yet a different dictionary. I predict that if you retrieve them from params, you’ll find that the values are the correct shape but have all zero contents.

There’s another bug that I didn’t notice the first time I looked:

Check the arguments you are passing to optimize. One of them is incorrect and that’s probably what causes this problem.

1 Like

Thank you for the good info. I am getting a cannot reshape error (attached).

Code:

{moderator edit - solution code removed}

What does the variable params have to do with anything? That is not defined at that point in this function, right?

the directions within the model function states: “Retrieve parameters w and b from dictionary “params””

The first rule of programming is: believe the code, not the comments. So where is the variable params defined? What variable received the relevant return values from the call to the optimize function? In the code you showed, it was parameters, right? That is not the same variable name.

But note that the comments also told you this:

    #(≈ 1 line of code)
    # Gradient descent 
    # params, grads, costs = ...

So if you’re going to follow the instructions, you have to do it consistently. It doesn’t work if you follow them some places and then not in others.

But the fundamental point is that you can name the variables fred, barney and wilma if you like. The actual names don’t really matter as long as you use them consistently.

2 Likes

Yes @paulinpaloalto & @Chris7 , that’s one of the errors which is very prominent.