Need help with week 3 Programming Assignment

Excercise 5 - Compute Cost

logprobs = np.multiply(np.log(A2),Y)
cost = - np.sum(logprobs) 

What is the use of this piece of code ? When I copy pasted this in the exercise, I got wrong answer.

cost = -np.sum(Y * np.log(A2) + (1 - Y) * np.log(1 - A2)) / m

Then I tried this :point_up:, from previous assignment and it worked. It is same as written in Equation 13

𝐽=−1𝑚∑𝑖=1𝑚(𝑦(𝑖)log(𝑎[2](𝑖))+(1−𝑦(𝑖))log(1−𝑎[2](𝑖)))                ...(13)

If this is correct then what will be the value of logprobs.

Hello @g_paras
The value of logprobs = np.multiply(np.log(A2),Y) or logprobs = Y * np.log(A2) but the given code for cost (i.e. cost = - np.sum(logprobs)) is not complete but a part of the cost.
You have to compute the complete cost which you did by this:
cost = -np.sum(Y * np.log(A2) + (1 - Y) * np.log(1 - A2)) / m

Cost is J.

Hope this explanation clears your doubts.
All the best


Have you ever read this topic?