Error in Exercise 6 - compute_cost of Building_your_Deep_Neural_Network_Step_by_Step Assignment

I am trying to compute the cost using:
cost = -(1/m) * (Y * np.log(AL) + (1-Y) * np.log(1-AL))

The inputs to compute_cost method are Y and AL. But I am getting error as AssertionError: Not all tests were passed for compute_cost. Check your equations and avoid using global variables inside the function.

I even tried cost = -(1/m)*(np.multiply(Y,np.log(AL)) +np.multiply( (1-Y),np.log(1-AL))). But still I am receiving the same error.

Please help me rectify the issue.


Well, what value do you get for cost using your code as shown above? Did you try printing it out? I’m going to guess that at least one problem with it is that it is not scalar or 1 x 1 value. Why is that?

Note that np.multiply does exactly the same thing as *: both of those are “elementwise” multiply. So what you end up with after that is a 1 x m row vector. To get the scalar cost value, you need to then add up the elements of that vector, right?