Programming Machine Learning: matplotlib broadcast error on page 58

Hello, @tihnessa! Sorry for the slow reply. I was on travel.

Somehow, the code you’re using isn’t the same as in the current book and downloadable code. It’s not:

return 2 * np.matmul(X.T * (predict(X, w) - Y)) / X.shape[0]

but rather:

return 2 * np.matmul(X.T, (predict(X, w) - Y)) / X.shape[0]

(Note the comma after X.T, as opposed to the multiplication).

I have no idea what happened here. Maybe this was a bug in the book that I later fixed, and you have an older version of the book+code? Or maybe you were experimenting with the code and changed that line? In any case, that seems to be the issue.

Can you please confirm that you got it fixed?