Yes, this is a known problem with that test case. I filed a bug about this a while ago but it has not been addressed yet. The thread I linked is from Nov 2021 and I filed the bug in March 2023, when another student hit this issue.
If you consider the efficiency of the code, using A1
instead recomputing tanh(Z1)
is way more efficient. After you went to all that trouble to avoid unnecessarily computing logarithms in the cost function, computing
tanh
involves not one but two exponentials, right? Well, to be completely correct, the second exponential is not really necessary since it could be computed by division (multiplicative inverse), but you don’t really know what the np.tanh
code does.