W4_A1_Ex-5_ValueError: shapes (1,3) and (4,4) not aligned

Hello! I’ve been stuck in this exercise some days, I cannot see the error in my code. Im getting an error because of the dimensions of the matrices. This is what I did, and Im getting the error “ValueError: shapes (1,3) and (4,4) not aligned: 3 (dim 1) != 4 (dim 0)”, which comes form the linear_forward function, because when doing the dot product, the sizes of the matrices do not match. However, I cannot see my error. I think that the error comes from the matrix A, but still I cannot find what it is.
I would really appreciate the help

{Moderator’s Edit: Solution Code Removed}

Hey @Pamela_Carolina_Diaz,
A couple of quick questions.

  • Why are you appending list(cache) instead of cache?
  • You have mentioned that the error arises from linear_forward function. Are you referring to the linear_activation_forward function?

P.S. - Posting solution code publicly is strictly against the community guidelines. Please refrain from doing so in the future. You are more than welcome to share your error stack instead.

Cheers,
Elemento

In addition to the issues that Elemento mentioned, remember that indentation is critical to the syntax in python. The way you have indented the code, the handling for the output layer is getting executed on every iteration of the loop over the hidden layers. That’s probably what is causing that specific error.

Here’s a thread which gives the dimensional analysis for that test case, which will give you a clearer view of the meaning of that error.

that was the problem! thank you very much! is working now