Course 1, week 2 assignment costs

My code passed all the tests and right at the end when we would merge everything to produce the final model I get an error that my costs is of the wrong length.

I tried to understand what could had gone wrong, but I cannot find a way I could reduce the costs into a list with one scalar number.

The definition we used earlier gives a list of all the costs, so I am not sure how we can change its output.
When I add a new “costs” variable which equals to [np.sum(costs)], it gives the wrong output.

A test program sets the number of iterations to 50. So, there should be only one “cost” in costs.
One possibility of this error is that you override “num_iterations” to 2000, which creates 20 cost data.
Please make sure that, when you call optimize(), you need to use parameters passed to this model() and should not override any.

Oh so the number of iterations were for the optimise function so I shouldnt use the number of iterations used for the general model because of the modulo 100 used in the iterations right?

I fixed it but now dw is a list(i think) instead of an array

Oh so the number of iterations were for the optimise function so I shouldnt use the number of iterations used for the general model because of the modulo 100 used in the iterations right?

I’m afraid that you may not catch my point. Important thing is NOT who set what parameters. You need to write a code that works for any cases. Do not hard-code any to assume specific case. A grader program will use different values, of course.

fixed it but now dw is a list(i think) instead of an array

If you look at the Traceback, you should understand that the type for w is array, and the shape is correct. But, the value is not.

I’m afraid that you still have hard-coded values in your model() or optimize().

I cannot find any hard-coded values and I followed the steps quite closely. Could I look at a solution to the code please?

When you call “optimize()” in “model()”, didn’t you set “FIXED” values for num_iterations, learnnig_rate and print cost ? That"s “hard-coded”. You should not override any.
What you are requested is to use passed values as is.

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):

2000, 0.5, False,… all are default values IF those parameters are not passed from a caller. You do not need to care any.

Now I understand thank you