Exercise 8 of week 2 -Model

The individual cost values are scalars, but the model function returns an array of them: one per every 100 iterations. That is the variable costs. If the number of elements in that array is incorrect (which is what this error message is telling you), it means your code did not run the correct number of iterations that were requested by the parameters being passed into model at the top level. So how could that happen? The most usual cause is “hard-coding” the number of iterations on the call from model to optimize. There should not be any “=” equal signs in the parameter list that you pass to optimize, right? Because if there are, it means you are ignoring the requested values.

Actually you can see the bug in the code you showed. You pass num_iterations=2000, so you will always do 2000 iterations and get 20 elements in the costs array regardless of what the arguments request. You’ve made the same mistake with respect to the other optional parameters to optimize as well.