Course 1 Week 2 assignment exercise 8

{moderator edit - solution code removed}

For exercise 8, in creating a model for linear regression, I get the error
ValueError: cannot reshape array of size 2 into shape (4,1)
w = w.reshape(X.shape[0], 1)

i can’t seem to figure out why?

Because X is not a local variable in the function model. So you are picking up a global value that has nothing to do with what is actually happening there.

In these courses it is always a mistake to reference global variables from the local scope of any of your functions.

1 Like