W4_A1_Wrong shape for variables

Exercise 05 : The print output is correct AL = [[0.03921668 0.70498921 0.19734387 0.04728177]], but unit test delivery:

Error: The function should return a numpy array. in variable 2. Got type: <class ‘numpy.ndarray’> but expected type <class ‘tuple’>
Error: Wrong shape for variable 0.
Error: Wrong shape for variable 1.
Error: Wrong shape for variable 2.
Error: Wrong shape for variable 1.
Error: Wrong output for variable 0.
Error: Wrong output for variable 1.
Error: Wrong output for variable 2.
Error: Wrong output for variable 1.
0 Tests passed
3 Tests failed

Can you help me please?

1 Like

The problem might be here:

def linear_activation_forward(A_prev, W, b, activation):

Returns:
A -- the output of the activation function, also called the post-activation value 
cache -- a python tuple containing "linear_cache" and "activation_cache";
         stored for computing the backward pass efficiently

The return should be a python tuple here, if its not so!

Here is my output from that test:

AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
All tests passed.

So you can see that my AL values are the same as yours. So as Gent says, the most likely place to look for problems is in the other return value, which is caches.

The other consideration is to notice that there are actually two test cases there: the one you can see in the notebook and then another one that is in the file public_tests.py. It’s the second one that is failing. So maybe you “hard-coded” things somehow, such that they work for one test but not the other.

I added some print statements to my code and here’s what I get for the visible test case in the notebook:

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]]

Check the type and length of caches and caches[-1] in your case and see if they match what I showed.

2 Likes

Ok, The assignment has already been evaluated, but I am going to do debugging in my environment. Thank you very much.

Ok, The assignment has already been evaluated, but I am going to do debugging in my environment. My mistake was calling sigmoid directly without returning the cache. I should have called the predefined function.

1 Like