I spend number of days in finding out of mistakes . I am getting the correct costs (even for 2499 iterations) and even use the correct W1,W2,b1,b2 but I am getting the error :
“Wrong shape for variable 0”.Please sir , tell me what does this error mean and how I can remove it.

Following text appear as result of execution of my code.

Cost after iteration 1: 0.6926114346158594
Cost after first iteration: [0.69304974]
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Error: Wrong shape for variable 0.
Cost after iteration 1: 0.6915746967050506
Cost after iteration 2: 0.6524135179683452
3 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in
3 print("Cost after first iteration: " + str(costs[0]))
4
----> 5 two_layer_model_test(two_layer_model)

~/work/release/W4A2/test_utils.py in multiple_test(test_cases, target)
140 print(’\033[92m’, success," Tests passed")
141 print(’\033[91m’, len(test_cases) - success, " Tests failed")
→ 142 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
143

AssertionError: Not all tests were passed for two_layer_model. Check your equations and avoid using global variables inside the function.

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.

Notice that everything is the same except the second line. I’m worried that is where the problem is: note that in your case the value prints with brackets around it. That might also explain why you get that error about the shape being wrong.

I added the following statements right before the “return” statement in my two_layer_model code:

It looks like your costs values have the correct type and values, so that is apparently not the problem. If you look at the output carefully, you can see that it’s the public test that fails. You can examine the code in the file public_tests.py to see how it works. It’s getting a datatype mismatch, but doesn’t tell us which variable. The other return value is parameters, which is supposed to be a dictionary containing numpy arrays. Try adding some more print statements to show the type and values of parameters.

I did that in my code and here’s what I get:

Cost after iteration 1: 0.6926114346158595
type(parameters) <class 'dict'>
type(parameters['W1']) <class 'numpy.ndarray'>
parameters['W1'].shape (7, 12288)
Cost after first iteration: 0.693049735659989
Cost after iteration 1: 0.6915746967050506
type(parameters) <class 'dict'>
type(parameters['W1']) <class 'numpy.ndarray'>
parameters['W1'].shape (4, 10)
Cost after iteration 1: 0.6915746967050506
type(parameters) <class 'dict'>
type(parameters['W1']) <class 'numpy.ndarray'>
parameters['W1'].shape (4, 10)
Cost after iteration 1: 0.6915746967050506
type(parameters) <class 'dict'>
type(parameters['W1']) <class 'numpy.ndarray'>
parameters['W1'].shape (4, 10)
Cost after iteration 2: 0.6524135179683452
type(parameters) <class 'dict'>
type(parameters['W1']) <class 'numpy.ndarray'>
parameters['W1'].shape (4, 10)
All tests passed.

No values are are not hard-coded since they are computed by the functions defined on the previous homework. As for the order of backprop I’ve called linear_activation_backward first with dA2 activating "sigmoid" and then with dA1 on "relu". Is that what you mean?

The way you state that worries me a little: yes, that’s the correct function to use, but note that you do not have to manually “copy” that function cell over to this notebook. All the “Step by Step” functions are provided for you using an “import” command. Hand-copying the previous functions will cause problems, but not so much on the two_layer_model case …

I’m sure Rashmi will be able to see what is going on from your notebook.

" #(≈ 1 line of code)\n",
" cost = compute_cost(A2, Y)\n",
" costs.append(cost)\n"

The appending of the cost to the costs array is done by the template itself, which is only done after every 100 iterations. But it seems, you have done it on every single iteration, and that is why the costs array ends up being in the wrong size.