DLS1 week 4 Assignement exercise 5 error numpy array type

Hi,

I am stuck at exercise 5 in the graded assignement.
The output of L_model_forward seems correct:
The values of AL and dimensions correspond to the expected output.


I have checked all dimensions of every W and b and A, and they correspond to this thread.
I have checked the data type for all W b and A, all are arrays.
Where could my error message originate from? the cache? I do not find a way to QC the cache.
Here are my error messages:


Thank you all for your comments

For starters, note that there are (at least) two separate test cases here: the “2hidden” test case and then the one called L_model_forward_test, which comes from the file public_tests.py. Your code generated the correct value for AL, but the failure messages are all coming from the other test, right? And those messages seem to be mostly about wrong types, rather than wrong values. In order to interpret those messages, you’ll need to look at that other test.

FWIW, I added logic to my code to print the A^{[l]} values for every layer. Here’s what I get from running that test cell:

A1 = [[0.         3.18040136 0.4074501  0.        ]
 [0.         0.         3.18141623 0.        ]
 [4.18500916 0.         0.         2.72141638]
 [5.05850802 0.         0.         3.82321852]]
A2 = [[ 2.2644603   1.09971298  0.          1.54036335]
 [ 6.33722569  0.          0.          4.48582383]
 [10.37508342  0.          1.63635185  8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A1 = [[0.         3.18040136 0.4074501  0.        ]
 [0.         0.         3.18141623 0.        ]
 [4.18500916 0.         0.         2.72141638]
 [5.05850802 0.         0.         3.82321852]]
A2 = [[ 2.2644603   1.09971298  0.          1.54036335]
 [ 6.33722569  0.          0.          4.48582383]
 [10.37508342  0.          1.63635185  8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A1 = [[0.         3.18040136 0.4074501  0.        ]
 [0.         0.         3.18141623 0.        ]
 [4.18500916 0.         0.         2.72141638]
 [5.05850802 0.         0.         3.82321852]]
A2 = [[ 2.2644603   1.09971298  0.          1.54036335]
 [ 6.33722569  0.          0.          4.48582383]
 [10.37508342  0.          1.63635185  8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A1 = [[0.         3.18040136 0.4074501  0.        ]
 [0.         0.         3.18141623 0.        ]
 [4.18500916 0.         0.         2.72141638]
 [5.05850802 0.         0.         3.82321852]]
A2 = [[ 2.2644603   1.09971298  0.          1.54036335]
 [ 6.33722569  0.          0.          4.48582383]
 [10.37508342  0.          1.63635185  8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
 All tests passed.

So you can see that it runs the same tests multiple times from the public test function, but it’s checking different things. Do your values look the same as what I show for the later tests? It’s possible you have bugs that are causing the global data to get overwritten.

Hi Paul,

Thank you for picking this up. Please see below my result when I print A1, A2 for every value of l.
My A1 and A2 are identical to yours, and my AL too. Then the same error message prints out. However, in my result I do not see A3 (which should be AL, I have printed L out too). As python is zero-based, why does your loop go until A3?

Thank you for your help!

The output layer is not handled in the for loop: it is handled after you fall out of the loop. It needs to be handled as a separate step because it is the only layer that uses sigmoid as the activation function, right? So the for loop covers the “hidden” layers and then the output layer is handled separately after you finish the loop. You must have that part correct if your AL value prints correctly. That print statement was provided by the test case. Notice that you don’t see the AL value for the test that is run from public_tests.py, so you just didn’t add the extra print statement for the output layer in your code.

Hi Paul,

I see what you mean, I did not print out the result for A3.

Correct, the error messages come from L_model_forward.

Ok, how to look at public_test.py? Or what should I look at? I am not sure.

Thanks a lot,

If you want to look at the second test, click “File → Open” and then look at public_tests.py and test_utils.py, although that may not be so simple to figure out.

Hi Paul,

Thank you, I have checked public_tests.py and carefully compared the expected result to mine. However, I still do not see where the mismatch is.
I have output my caches, and they are identical to the one in public_tests.py. I have printed out the class of each object (apart from Z, but it should be the same as A) and they are all numpy.ndarray:

Yet, I still do not understand where the mismatch in “type” comes from.

I see 2 possible origins to my problem:

  1. Indexation. As much as I understand, each cache contains (A_prev,W,b,Z), in that order.
    So for iteration 1:
    cache 1= X, W1, b1, Z1
    iteration 2:
    cache 2= A1, W2, b2, Z2…
    Am I correct?
  2. Cache format/type. I have printed out type(caches) and it gives me a list. Is it correct?
    Maybe I do not know how to concatenate cache, but I have tried with different brackets or no brackets:
    caches=[caches,cache]

I am running out of ideas, what else can I check?
Thank you very much for your help,

Best,