Week 4 Prog Assignment 2- Exercise 1 - two_layer_model

Week 4: Prog. Assignment 2 Exercise 1 -two_layer_model
I got the following error when testing the two_layer_model. I already checked for any global variable being used within the functions and didn’t find them.
Lab ID: buzrzljvsoyo
Any assistance would be highly appreciated.
Regards!

Cost after iteration 1: 0.6926114346158594
Cost after first iteration: 0.693049735659989
Cost after iteration 1: 0.6915746967050506
Error: Datatype mismatch. in variable 0. Got type: <class ‘numpy.float64’> but expected type <class ‘numpy.ndarray’>
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 2: 0.6524135179683452
3 Tests passed
1 Tests failed
AssertionError: Not all tests were passed for two_layer_model. Check your equations and avoid using global variables inside the function.

Did you copy over your functions from the Step by Step exercise? If so, that was a mistake. You can just call them: you don’t need to “copy/paste” them.

I didn’t copy the functions from the step-by-step code.
I did go back to that notebook and checked if any global variables were used.
Any further assistance?
Thank you!

Well, the error message is telling you that in some case you are returning a scalar float value, where it expects a numpy array. The one case in which I thought that might happen is the cost value. The compute_cost function they provide here returns a single element array for the cost, but in the Step by Step exercise, you can pass the grader either way.

So it must be some other case in which you are returning the wrong thing. Here is my output from running that test cell and the cost values seem to agree with yours:

Cost after iteration 1: 0.6926114346158595
Cost after first iteration: 0.693049735659989
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 2: 0.6524135179683452
 All tests passed.

Maybe it’s just time to look at your code. We can’t do that here in a public thread, but I will send you a DM (Direct Message) about how to proceed with that.

Hi @Jorge_Pesantez ,

All the functions used in the two_layer_model() are provided, so the code you need to write is just calling those functions. It could be that the execution environment is out of date. Try refreshing the kernel and clear output, then rerun the code from start.