Cannot complete step in Programming assignment for week 4

When creating a post, please add:

  • Week # must be added in the tags option of the post.
  • Link to the classroom item you are referring to:
  • Description (include relevant info but please do not post solution code or your entire notebook)
  • Link- posting assignment links, grade cells codes is against community guidelines
  • def L_model_forward(X, parameters): When this function is tested, I get:

    It is difficult, because its not really possible to add extra debug statements.
    This is an example of one of my lines. Not sure why it doesn’t work, AL, cache = linear_activation_forward(A_prev, parameters[f"W{l}“], parameters[f"b{l}”], activation=“relu”)

Inner dimensions must match for dot product to work. Here’s an example:

>>> a = np.random.rand(3,4)
>>> b = np.random.rand(4, 5)
>>> np.dot(a, b).shape
(3, 5)
>>> c = np.random.rand(5,4)
>>> np.dot(a, c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 200, in dot
ValueError: shapes (3,4) and (5,4) not aligned: 4 (dim 1) != 5 (dim 0)
>>> 

Here’s a thread which goes through the “dimensional analysis” for that “2hidden” test case, so that you can see what is supposed to be happening. Then you need to track backwards to figure out where your code went off the rails.

Note that the bug is not in the lower level routine: it is in your L_model_forward logic. You are passing mismatching parameters down to the lower level functions.

Thank you to Paul and Balaji! You are both awesome and helped me get the answer. What a relief! So close to the end of the course! Happy Holidays!

1 Like