Course 1 - week 2 assignment AssertionError: Wrong length for d['costs']. 20 != 1

That error usually means that you are “hard-coding” the number of iterations and perhaps other parameters someplace. You’ve done 2000 iterations which is why you get 20 cost values, but the test case is asking for a smaller number of iterations. So how could that happen? Typically this happens when you call optimize from model: there should be no equal signs in any of the parameters being passed to that function, because that means you are ignoring the parameters being passed in at the top level to the model function. Another way to “hard-code” parameters is not to pass the learning rate, number of iterations and print flag on the call to optimize from model, since that would mean you will use the default values of those parameters which were declared in the definition of the optimize function. In other words, you’d be ignoring the actual requested values and using the defaults, which is another form of “hard-coding”. Although note that the default for number of iterations declared in the definition of optimize is 100, so that’s probably not the specific bug you have in this case.

10 Likes