Course 2 Week 1: assignment gradient checking

I’m basically stuck on the last exercise, number 4.

What I do is the following:

  • theta_plus is the copy of the parameters
  • theta_plus [i] is equal to theta_plus[i] + epsilon
  • J_plus is obtained by calling the function forward_propagation_n(X, Y, vector_to_dictionary(theta_plus))

I keep getting the following error cannot reshape array of size 1 into shape (5,4)

Any help?

My guess is the theta_plus value that you are passing to vector_to_dictionary is a scalar or perhaps a 1D array with one element. Try printing the type and shape of that variable right before the line that “throws”.

print(type(theta_plus))
print(theta_plus.shape)

Of course if my theory is right, that second print statement will also “throw” :nerd_face:

Also note that you filed this under DLS Course 1, so I moved it for you to Course 2 by using the little “edit pencil” on the title.

If my suggestion is not enough to get you there, then the next step would be to actually show us the full output you are getting including the exception trace …