Week 1, Assignment 2, Exercise 2 Sample

I cannot for the life of me figure out what the compiler dislikes about my code. Does anyone know what’s the matter? I included debugging prints.

I think the most likely problem is that eitiher your code for “x = …” or "a_prev = … " is incorrect.

1 Like

The problem could be on the second iteration, when ‘x’ is re-defined inside the loop.

2 Likes

Right! I added the following print statement in the loop right before the line that “throws” in your test case:

print(f"Wax {Wax.shape} x {x.shape} Waa {Waa.shape} a_prev {a_prev.shape}")

Here’s the output I see in the first few iterations:

vocab_size = 27
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)
y.shape (27, 1)
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)
y.shape (27, 1)

So it looks like there are at least two problems with your code:

You are apparently substituting a_prev for x.

Your a_prev is a 1D array when it should be a 2D array.

So how could that happen?

That was it. I hadn’t redefined x correctly later in the loop. That was throwing off my code, and I didn’t think to look there. Thanks.