C5.W1.P1.UNQ_C2 - rnn_forward Error "too many indices for array" vs ""Wrong shape for a. Expected: ..."

Hello there, I am having the following problem in the course 5, week 1, assignment 1, in the cell UNQ_C2, as follows:

Error

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-102-0cebf7854aa8> in <module>
      9 parameters_tmp['by'] = np.random.randn(2, 1)
     10 
---> 11 a_tmp, y_pred_tmp, caches_tmp = rnn_forward(x_tmp, a0_tmp, parameters_tmp)
     12 print("a[4][1] = \n", a_tmp[4][1])
     13 print("a.shape = \n", a_tmp.shape)

<ipython-input-101-e6819b85944b> in rnn_forward(x, a0, parameters)

---> 64         a[:,:,t] = a_next[:,:,t]
     65 
     66         # Save the value of the prediction in y (≈1 line)

IndexError: too many indices for array

Problem

How can this be, when the dimensions are the same?


a_next.shape = (5, 10)
a.shape = (5, 10)

Workaround (Wrong)

This workaround seems to work (yey!) but causes a different issue later with the assertions

a = a_next

Workaround-cased new error

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-100-0cebf7854aa8> in <module>
     18 
     19 #UNIT TEST
---> 20 rnn_forward_test(rnn_forward)

~/work/W1A1/public_tests.py in rnn_forward_test(target)
     71     a, y_pred, caches = target(x_tmp, a0_tmp, parameters_tmp)
     72 
---> 73     assert a.shape == (n_a, m, T_x), f"Wrong shape for a. Expected: ({n_a, m, T_x}) != {a.shape}"
     74     assert y_pred.shape == (n_y, m, T_x), f"Wrong shape for y_pred. Expected: ({n_y, m, T_x}) != {y_pred.shape}"
     75     assert len(caches[0]) == T_x, f"len(cache) must be T_x = {T_x}"

AssertionError: Wrong shape for a. Expected: ((7, 8, 13)) != (7, 8)

Any pointers will be much appreciated.

Thanks!

Sorry I cannot check this in detail right now, but I think a and a_next should not be the same size.

Thanks for the pointer @TMosh , I zeroed in your observation and fixed the problem.

I was missing the Tx in a.shape

Create a 3D array of zeros, 𝑎a of shape (𝑛𝑎,𝑚,𝑇𝑥)(na,m,Tx)

So indeed, a includes the Time step while a_next does not.

Thank you!