[Workaround] C1_W2_Linear_Regression ValueError

If you pass all tests in the notebook but get

Cell #8. Can’t compile the student’s code. Error: ValueError(‘shapes (1,4) and (1,4) not aligned: 4 (dim 1) != 1 (dim 0)’)

when the assignment gets graded, put this line of code on the first line of every graded function:

w = np.squeeze(w)

For some reason, w is an ndarray when the function is being graded and not a scalar.

1 Like

Nice detective work, @Stuart_Fong1! I’ll report this to course staff so they can update the assignment.

FYI, I tried submitting my implementation, which passed fine, so you can implement this so that it works with w being an array or a scalar. I suspect the developers of the assignment might have even intended that it should work with both, since I see a test in the public tests, compute_cost_test where it tests with: initial_w = np.array([2.]). But, of course, everything in the assignment says w is a scalar, so either the assignment needs to be updated to say it should support both, or the grader needs to be updated to only test with scalars.

If you’re curious, you might want to click on the “Click for hints” link in the assignment to see an approach that should work even if w is an array

1 Like

Hi, I didn’t have the issue but I’m curious about why this happened for some people.
Please, could we maybe have any follow-up on this issue?
Thank you!