W2,A2,Ex-8 assignment problem

It keep telling me about the wrong length costs, but I just use the optimize function which passed the test in the early code. I can’t see where the problem is.

Hi @rdf5skbz8x

In the model() function, the dimension used for setting the size of W is extracted from the training data, is it done correctly?

the size of w is X_train.shape[0], namely the first coordinate of (num_px * num_px * 3, number of examples) , 64643. Is that right?

Hi @rdf5skbz8x ,

Check the parameters passed to the optimize() are correct. As you are training the model, so it should use X_train and Y_train of model() not the test data.

It seems that I have found the problem. The length of costs turns out to be 20 instead of 1 as required is because that the optimize function is defined to append one more coordinate every 100 times, and the enumeration is 2000, so the length is 100 divide 2000 equals 20. I wonder how I can extract just the last coordinate in the meanwhile of optimizing ( the assignment requirement is to use one line of code).

Hi @rdf5skbz8x ,

The code block for recording the cost is provided, and it shouldn’t be changed. Any of the input arguments for optimize() function could be different depending on the test case requirement.
The code you are required to fill in are enclosed with a pair of comment lines:

YOUR CODE STARTS HERE

YOUR CODE ENDS HERE

The question is why you are passing 2000 as the iteration count to optimize instead of the value that is actually part of that test case? That’s the bug: you are “hard-coding” some of the parameters when you call optimize.

If you are new to python, you should spend some time reading up on how optional or “named” or “keyword” parameters work in python. Try googling “python keyword parameters” to learn about that.

Figured it out. Thank you! :slight_smile: