# Neural networks: generating g prime(z) in back propagation

I am doing Andrew Ng's excellent new Deeplearning course. I have an issue with implementing back propagation in a one hidden layer network that looks like this:

I am trying to derive the derivative of Z1 using the formula:

My understanding is that g prime Z1 in this formula is the derivative of g(z) with respect to Z which I believe is

    sigmoid(Z) * (1-sigmoid(Z))


where the function sigmoid generates the sigmoid function with respect to Z. My final equation looks like this:

  dZ1 = np.dot(W2.T, dZ2) * (sigmoid(Z1)*(1-sigmoid(Z1)))


Where Z1 is the output of the first (and only) hidden layer.

Where am I going wrong?

• I don't see anything obviously wrong (except Z1 is not the output of the layer, it is the "logit" and A1 is the output, A1 = sigmoid(Z1)). What is happening that makes you think your code is wrong? Commented Aug 25, 2017 at 9:15
• The course provides expected answers which up to this point, I have been getting right. However, for this section of the exercise, my result for all parameters that involve dZ1 are wrong (but the other parameters are correct). Commented Aug 25, 2017 at 9:21
• OK, I think I see the problem. You have made an incorrect assumption about the network architecture, take a look at the feed-forward logic again. I don't want to break the course honour code and spell it out. Note I made the same error in my previous comment, because I assumed you were correct . . . Commented Aug 25, 2017 at 9:28
• I took the course too. The honour code suggests that I should not actually debug or write answers directly on coursework, but I think hints and general knowledge about backprop are OK. So also asking about a similar network you were implementing in a different approach or "why does it work like this" are fine. I suggest don't post your answer here because that would be publishing a partial answer to course materials. Commented Aug 25, 2017 at 9:48
• If you have enough time to write about a different network, without using the course materials, but with the same mistake in backprop, then I think a self-answer would be fine here, and not a violation of course honour code. There are literally dozens of posts like that here, that anyone could look up. However, it may not be worth your time. Commented Aug 25, 2017 at 9:52