Course 1, Week 3, Exercise 5

Hi mentor. I’m difficult to use np.dot instead of using np.multiply. I want to try it.
I wrote cost statement as follows:

Compute the cross-entropy cost

# (≈ 2 lines of code)
# logprobs = ...
# cost = ...
# YOUR CODE STARTS HERE

#logprobs = np.multiply(np.log(A2),Y) + np.multiply(np.log(1-A2), 1-Y)
#cost = (-1/m)*np.sum(logprobs)  
cost = (-1/m) * np.sum(np.dot(Y, np.log(A2)) + np.dot(1-Y, log(1-A2)))
# YOUR CODE ENDS HERE

Please help me. Thanh you very much.

That will throw an error (as I’m sure you discovered). The problem is that the dimensions don’t work for dot products without a transpose. Please see this thread for some examples.