Week 4_Assignment 5


I am facing this error please help me with it as the AL in getting generated but dont know what other test cases have to be passed

Well, you can look at the test case code to figure out what else is being checked. It’s in the file public_tests.py, as you can see in the exception trace. Click “File → Open” and have a look.

Yes, your A2 value as shown agrees with the expected value. But notice that the other return value is the caches array. Perhaps that is incorrect. That will be critical to the back propagation code that we will write next.

I am still not able to get to the answer can you please help me with that

I have the cache also correct this is the cache matrix that I have generated:
[((np.array([[-0.31178367, 0.72900392, 0.21782079, -0.8990918 ],
[-2.48678065, 0.91325152, 1.12706373, -1.51409323],
[ 1.63929108, -0.4298936 , 2.63128056, 0.60182225],
[-0.33588161, 1.23773784, 0.11112817, 0.12915125],
[ 0.07612761, -0.15512816, 0.63422534, 0.810655 ]]),
np.array([[ 0.35480861, 1.81259031, -1.3564758 , -0.46363197, 0.82465384],
[-1.17643148, 1.56448966, 0.71270509, -0.1810066 , 0.53419953],
[-0.58661296, -1.48185327, 0.85724762, 0.94309899, 0.11444143],
[-0.02195668, -2.12714455, -0.83440747, -0.46550831, 0.23371059]]),
np.array([[ 1.38503523],
[-0.51962709],
[-0.78015214],
[ 0.95560959]])),
np.array([[-5.23825714, 3.18040136, 0.4074501 , -1.88612721],
[-2.77358234, -0.56177316, 3.18141623, -0.99209432],
[ 4.18500916, -1.78006909, -0.14502619, 2.72141638],
[ 5.05850802, -1.25674082, -3.54566654, 3.82321852]])),
((np.array([[0. , 3.18040136, 0.4074501 , 0. ],
[0. , 0. , 3.18141623, 0. ],
[4.18500916, 0. , 0. , 2.72141638],
[5.05850802, 0. , 0. , 3.82321852]]),
np.array([[-0.12673638, -1.36861282, 1.21848065, -0.85750144],
[-0.56147088, -1.0335199 , 0.35877096, 1.07368134],
[-0.37550472, 0.39636757, -0.47144628, 2.33660781]]),
np.array([[ 1.50278553],
[-0.59545972],
[ 0.52834106]])),
np.array([[ 2.2644603 , 1.09971298, -2.90298027, 1.54036335],
[ 6.33722569, -2.38116246, -4.11228806, 4.48582383],
[10.37508342, -0.66591468, 1.63635185, 8.17870169]])),
((np.array([[ 2.2644603 , 1.09971298, 0. , 1.54036335],
[ 6.33722569, 0. , 0. , 4.48582383],
[10.37508342, 0. , 1.63635185, 8.17870169]]),
np.array([[ 0.9398248 , 0.42628539, -0.75815703]]),
np.array([[-0.16236698]])),
np.array([[-3.19864676, 0.87117055, -1.40297864, -3.00319435]]))]

This matches exactly with the array to be generated by the test script I dont understand why this is happening??

I added a bunch of print statements to my L_model_forward and here’s what I get, including my complete caches variable (notice that there are several test cases but they seem to be repeating the same tests):

l = 3
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A3.shape = (1, 4)
type(caches) = <class 'list'>
len(caches) = 3
type(caches[-1]) = <class 'tuple'>
len(caches[-1]) = 2
[((array([[-0.31178367,  0.72900392,  0.21782079, -0.8990918 ],
       [-2.48678065,  0.91325152,  1.12706373, -1.51409323],
       [ 1.63929108, -0.4298936 ,  2.63128056,  0.60182225],
       [-0.33588161,  1.23773784,  0.11112817,  0.12915125],
       [ 0.07612761, -0.15512816,  0.63422534,  0.810655  ]]), array([[ 0.35480861,  1.81259031, -1.3564758 , -0.46363197,  0.82465384],
       [-1.17643148,  1.56448966,  0.71270509, -0.1810066 ,  0.53419953],
       [-0.58661296, -1.48185327,  0.85724762,  0.94309899,  0.11444143],
       [-0.02195668, -2.12714455, -0.83440747, -0.46550831,  0.23371059]]), array([[ 1.38503523],
       [-0.51962709],
       [-0.78015214],
       [ 0.95560959]])), array([[-5.23825714,  3.18040136,  0.4074501 , -1.88612721],
       [-2.77358234, -0.56177316,  3.18141623, -0.99209432],
       [ 4.18500916, -1.78006909, -0.14502619,  2.72141638],
       [ 5.05850802, -1.25674082, -3.54566654,  3.82321852]])), ((array([[0.        , 3.18040136, 0.4074501 , 0.        ],
       [0.        , 0.        , 3.18141623, 0.        ],
       [4.18500916, 0.        , 0.        , 2.72141638],
       [5.05850802, 0.        , 0.        , 3.82321852]]), array([[-0.12673638, -1.36861282,  1.21848065, -0.85750144],
       [-0.56147088, -1.0335199 ,  0.35877096,  1.07368134],
       [-0.37550472,  0.39636757, -0.47144628,  2.33660781]]), array([[ 1.50278553],
       [-0.59545972],
       [ 0.52834106]])), array([[ 2.2644603 ,  1.09971298, -2.90298027,  1.54036335],
       [ 6.33722569, -2.38116246, -4.11228806,  4.48582383],
       [10.37508342, -0.66591468,  1.63635185,  8.17870169]])), ((array([[ 2.2644603 ,  1.09971298,  0.        ,  1.54036335],
       [ 6.33722569,  0.        ,  0.        ,  4.48582383],
       [10.37508342,  0.        ,  1.63635185,  8.17870169]]), array([[ 0.9398248 ,  0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676,  0.87117055, -1.40297864, -3.00319435]]))]
AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
l = 3
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A3.shape = (1, 4)
type(caches) = <class 'list'>
len(caches) = 3
type(caches[-1]) = <class 'tuple'>
len(caches[-1]) = 2
[((array([[-0.31178367,  0.72900392,  0.21782079, -0.8990918 ],
       [-2.48678065,  0.91325152,  1.12706373, -1.51409323],
       [ 1.63929108, -0.4298936 ,  2.63128056,  0.60182225],
       [-0.33588161,  1.23773784,  0.11112817,  0.12915125],
       [ 0.07612761, -0.15512816,  0.63422534,  0.810655  ]]), array([[ 0.35480861,  1.81259031, -1.3564758 , -0.46363197,  0.82465384],
       [-1.17643148,  1.56448966,  0.71270509, -0.1810066 ,  0.53419953],
       [-0.58661296, -1.48185327,  0.85724762,  0.94309899,  0.11444143],
       [-0.02195668, -2.12714455, -0.83440747, -0.46550831,  0.23371059]]), array([[ 1.38503523],
       [-0.51962709],
       [-0.78015214],
       [ 0.95560959]])), array([[-5.23825714,  3.18040136,  0.4074501 , -1.88612721],
       [-2.77358234, -0.56177316,  3.18141623, -0.99209432],
       [ 4.18500916, -1.78006909, -0.14502619,  2.72141638],
       [ 5.05850802, -1.25674082, -3.54566654,  3.82321852]])), ((array([[0.        , 3.18040136, 0.4074501 , 0.        ],
       [0.        , 0.        , 3.18141623, 0.        ],
       [4.18500916, 0.        , 0.        , 2.72141638],
       [5.05850802, 0.        , 0.        , 3.82321852]]), array([[-0.12673638, -1.36861282,  1.21848065, -0.85750144],
       [-0.56147088, -1.0335199 ,  0.35877096,  1.07368134],
       [-0.37550472,  0.39636757, -0.47144628,  2.33660781]]), array([[ 1.50278553],
       [-0.59545972],
       [ 0.52834106]])), array([[ 2.2644603 ,  1.09971298, -2.90298027,  1.54036335],
       [ 6.33722569, -2.38116246, -4.11228806,  4.48582383],
       [10.37508342, -0.66591468,  1.63635185,  8.17870169]])), ((array([[ 2.2644603 ,  1.09971298,  0.        ,  1.54036335],
       [ 6.33722569,  0.        ,  0.        ,  4.48582383],
       [10.37508342,  0.        ,  1.63635185,  8.17870169]]), array([[ 0.9398248 ,  0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676,  0.87117055, -1.40297864, -3.00319435]]))]
l = 3
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A3.shape = (1, 4)
type(caches) = <class 'list'>
len(caches) = 3
type(caches[-1]) = <class 'tuple'>
len(caches[-1]) = 2
[((array([[-0.31178367,  0.72900392,  0.21782079, -0.8990918 ],
       [-2.48678065,  0.91325152,  1.12706373, -1.51409323],
       [ 1.63929108, -0.4298936 ,  2.63128056,  0.60182225],
       [-0.33588161,  1.23773784,  0.11112817,  0.12915125],
       [ 0.07612761, -0.15512816,  0.63422534,  0.810655  ]]), array([[ 0.35480861,  1.81259031, -1.3564758 , -0.46363197,  0.82465384],
       [-1.17643148,  1.56448966,  0.71270509, -0.1810066 ,  0.53419953],
       [-0.58661296, -1.48185327,  0.85724762,  0.94309899,  0.11444143],
       [-0.02195668, -2.12714455, -0.83440747, -0.46550831,  0.23371059]]), array([[ 1.38503523],
       [-0.51962709],
       [-0.78015214],
       [ 0.95560959]])), array([[-5.23825714,  3.18040136,  0.4074501 , -1.88612721],
       [-2.77358234, -0.56177316,  3.18141623, -0.99209432],
       [ 4.18500916, -1.78006909, -0.14502619,  2.72141638],
       [ 5.05850802, -1.25674082, -3.54566654,  3.82321852]])), ((array([[0.        , 3.18040136, 0.4074501 , 0.        ],
       [0.        , 0.        , 3.18141623, 0.        ],
       [4.18500916, 0.        , 0.        , 2.72141638],
       [5.05850802, 0.        , 0.        , 3.82321852]]), array([[-0.12673638, -1.36861282,  1.21848065, -0.85750144],
       [-0.56147088, -1.0335199 ,  0.35877096,  1.07368134],
       [-0.37550472,  0.39636757, -0.47144628,  2.33660781]]), array([[ 1.50278553],
       [-0.59545972],
       [ 0.52834106]])), array([[ 2.2644603 ,  1.09971298, -2.90298027,  1.54036335],
       [ 6.33722569, -2.38116246, -4.11228806,  4.48582383],
       [10.37508342, -0.66591468,  1.63635185,  8.17870169]])), ((array([[ 2.2644603 ,  1.09971298,  0.        ,  1.54036335],
       [ 6.33722569,  0.        ,  0.        ,  4.48582383],
       [10.37508342,  0.        ,  1.63635185,  8.17870169]]), array([[ 0.9398248 ,  0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676,  0.87117055, -1.40297864, -3.00319435]]))]
l = 3
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A3.shape = (1, 4)
type(caches) = <class 'list'>
len(caches) = 3
type(caches[-1]) = <class 'tuple'>
len(caches[-1]) = 2
[((array([[-0.31178367,  0.72900392,  0.21782079, -0.8990918 ],
       [-2.48678065,  0.91325152,  1.12706373, -1.51409323],
       [ 1.63929108, -0.4298936 ,  2.63128056,  0.60182225],
       [-0.33588161,  1.23773784,  0.11112817,  0.12915125],
       [ 0.07612761, -0.15512816,  0.63422534,  0.810655  ]]), array([[ 0.35480861,  1.81259031, -1.3564758 , -0.46363197,  0.82465384],
       [-1.17643148,  1.56448966,  0.71270509, -0.1810066 ,  0.53419953],
       [-0.58661296, -1.48185327,  0.85724762,  0.94309899,  0.11444143],
       [-0.02195668, -2.12714455, -0.83440747, -0.46550831,  0.23371059]]), array([[ 1.38503523],
       [-0.51962709],
       [-0.78015214],
       [ 0.95560959]])), array([[-5.23825714,  3.18040136,  0.4074501 , -1.88612721],
       [-2.77358234, -0.56177316,  3.18141623, -0.99209432],
       [ 4.18500916, -1.78006909, -0.14502619,  2.72141638],
       [ 5.05850802, -1.25674082, -3.54566654,  3.82321852]])), ((array([[0.        , 3.18040136, 0.4074501 , 0.        ],
       [0.        , 0.        , 3.18141623, 0.        ],
       [4.18500916, 0.        , 0.        , 2.72141638],
       [5.05850802, 0.        , 0.        , 3.82321852]]), array([[-0.12673638, -1.36861282,  1.21848065, -0.85750144],
       [-0.56147088, -1.0335199 ,  0.35877096,  1.07368134],
       [-0.37550472,  0.39636757, -0.47144628,  2.33660781]]), array([[ 1.50278553],
       [-0.59545972],
       [ 0.52834106]])), array([[ 2.2644603 ,  1.09971298, -2.90298027,  1.54036335],
       [ 6.33722569, -2.38116246, -4.11228806,  4.48582383],
       [10.37508342, -0.66591468,  1.63635185,  8.17870169]])), ((array([[ 2.2644603 ,  1.09971298,  0.        ,  1.54036335],
       [ 6.33722569,  0.        ,  0.        ,  4.48582383],
       [10.37508342,  0.        ,  1.63635185,  8.17870169]]), array([[ 0.9398248 ,  0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676,  0.87117055, -1.40297864, -3.00319435]]))]
 All tests passed.

I didn’t check every single value, but it does appear that your caches values match what I show.

Maybe it’s time to look at your code. We can’t do that on a public thread, but check your DMs for a message from me.

To close the loop on the public thread, Yash and I had a DM conversation about the source code and it turned out there were some problems with changing the limits on the “for” loop over the hidden layers. The “range” on the loop is given to you in the template code and does not need to be changed.

For others who have problems with this test case, a good way to start the debugging process is to do the “dimensional analysis” to make sure you understand the test case and what should be happening at each layer. Here’s a thread which walks you through how to do that for this test case. It’s a good technique to have in your “toolbox” for cases like this.