I’m trying to run the cell 12 and 13 after “2.6 Learning parameters using batch gradient descent” and I’m getting a “TypeError: only size-1 arrays can be converted to Python scalars”.
But these two cell are code that is provided and I can’t edit it. I have passed the assessment given in the cell before.
Any ideas what the problem might be? All the code in the screenshot was provided in the assignment:
There is some thing wrong with your
def gradient_descent(x, y, w_in, b_in, cost_function, gradient_function, alpha, num_iters)
Please fix it, Otherwise send me your notebook as a personal message (click on my name and click on message) with notebook as attachment.
I’ll look into the issues and let you know.
The first step in debugging is always to figure out what the error message is actually telling you. If you look in detail at the line that “throws” and what the error message says, my guess is that it is telling you that the quantity J_history[-1] is not a scalar. I’m not a mentor for MLS and don’t have access to that notebook, but I’m guessing from the context that J_history is a list of the cost values every 10 iterations. So that probably means your J values are not scalars. At least that’s the first thing that I would investigate if I were in your shoes.
The first rule of debugging is “believe the error message”. If you don’t understand what it’s saying, that is the first problem you need to solve. Sometimes they can be a bit hard to understand, but this one was pretty clear.