Course 2, Week 1, Gradient Check assignment - Broadcasting Error

I have been struggling with this one a bit. Initially, I was getting the “wrong value” error at the end. Then I went back and made a change to gradient_check_n and now I am getting a broadcasting error when calculating the numerator.

Any hints as to what I might have wrong here?

operands could not be broadcast together with shapes (44,1) (47,1)

I am under the impression that “parameter_values” and “grads” should have matching dimensions. But if I run this code, i indicates otherwise:

X, Y, parameters = gradient_check_n_test_case()
gradients = backward_propagation_n(X, Y, cache)

parameters_values, _ = dictionary_to_vector(parameters)
grads = gradients_to_vector(gradients)

print(grads.shape)
print(parameters_values.shape)

prints:
(44, 1)
(47, 1)

Interesting. For what it’s worth, when I copy that test cell and insert the same code you show, here’s what I get

parameters_values.shape = (47, 1)
grads.shape = (47, 1)
There is a mistake in the backward propagation! difference = 0.2850931567761623

So why do you get a different dimension for your parameters? Are you sure that you did not edit any of the utility python files that come with this exercise?

Thanks. I had introduced an error into backward_propagation_n, which was messing up the gradients dictionary. Fixed and everything is good now.

Thanks again.