I passed all the tests but towards the end of the assignment where we are testing our optimizations with data, the backwards_propagation method keeps on spitting out an error at this line “da2 = np.dot(W3.T, dz3)” saying “ValueError: shapes (2,1) and (2,44) not aligned: 1 (dim 1) != 2 (dim 0)”.
I am getting an 88/100 currently.
This error means that the matrix multiplication is not possible because their shapes are not right. You should check their shapes and where those matrices are obtained from so you can fix the issue.
As Gent points out, there is a problem with your input matrices there. The usual cause for that type of problem is referencing global variables in the local scope of your functions, instead of using the formal parameters. The goal here is to write general functions that only depend on their inputs.
I am facing the same issue. The ValueError is coming from the backward_propagation function which is not defined in the W2 assignment. Moreover, the calling cell (6.1) is pre-written, including the inputs.
I did not touch anything inside and still getting this ValueError in 6.1, 6.2, and 6.3.
A perfectly correct subroutine can still throw errors if you pass it incorrect or mismatching data. This probably means there is something wrong with the code that you wrote. Check the sizes and shapes of the values that are produced by the random_mini_batches
call that is made within the model
function there. My guess is that you are referencing global variables instead of the passed parameters in your random_mini_batches
function (assuming it passes the unit tests earlier in the notebook).
Found the solution: in the random_mini_batches
function, while handling the last minibatch, writing int(m/inc)
worked for me. Previously I was using math.floor(m/inc)
.
Thank you for your response @paulinpaloalto
I would expect those two pieces of code to be functionally equivalent, since the “math” package is already imported early in this notebook. Are you sure you didn’t change anything else at the same time? E.g. referencing global variables?