# Error in compute_cost Planar data_classification with one hidden_layer

AssertionError: Wrong value. Expected: 0.5447066599017815 got: 3.6717539072244767

I tried both ways, np.dot, np.multiply. As per my understanding cost calculation is right. But I am getting the above error. could you help me.

``````np.multiply(np.log(A),Y)
``````

This is the example given, but need to apply transpose for multiplication.
For second part log (1-A) and (1-Y) multiplication, transpose as well
Then divide my number of examples as per cost formula.

Still I am getting the error.

Hello @Dr_Suresh_Kandulapat,

The above error means that the function does not compute the answer correctly. The test expected 0.544… from your work but the work gave back 3.672…

You tried both ways, but you didn’t say which way gave you that particular error. From my observation I think you did the `np.dot` approach and then got that error. Let’s focus on only the `np.dot` approach.

The shapes of A and Y are (1, m) where m is the number of examples. If we look at the code below:

``````A = np.array([0.1, 0.2, 0.3])
Y = np.array([0, 1, 1, ])
``````

Then there are 2 legal ways to “dot” them, which are A.T dot Y, and A dot Y.T.

``````print((np.dot(A.T, Y)).shape)  # --> (3, 3)
print((np.dot(A, Y.T)).shape)  # --> (1, 1)
``````

Only the 2nd way will give us a shape of (1, 1) which is effectively a scalar. Let’s go back to the equation we want to implement:

Obviously we want a scalar from the dot product. The first way transposes A into a shape of (m, 1) and dotting it with Y will result in a matrix of shape (m, m). Rather than a single and the correct scalar, we will be getting many but incorrect numbers, and summing those numbers up is likely to give a large but incorrect cost value.

I suggest you to check the shapes of your dot product results, and see if they are (1, 1).

Cheers,
Raymond

Yes, got it. thank you