# Neural Net and Deep learning week3 "Test the Model on the Planar Dataset"

Cost function works perfectly and passes all the tests but when appling it inside " Test the Model on the Planar Dataset" it gives me this error and i can’t seem to find out the problem.

in compute_cost(A2, Y)
21 # cost = …
22 # YOUR CODE STARTS HERE
—> 23 logprobs = np.multiply(np.log(A2), Y) + np.multiply((1 - Y), np.log(1 - A2))
24 cost = -1/m * np.sum(logprobs)
25

ValueError: operands could not be broadcast together with shapes (1,3) (1,400)

This is the problem i guess. This part of line doesnt seem to work on my case.

logprobs = np.multiply(np.log(A2),Y)

Hi mate, I believe your cost function formula is correct. However, I cannot be sure that the shape of your cost function is correct as well because value error is related to dimension mismatch. For those cases I prefer to apply print statement for A2 and Y so as to check whether they have same shape or not because they have to have same shape as well.

I checked the formula with test cases and it is correct. Also, where is the place of this error showed up? (Compute cost part or nn_model) I believe it is nn_model part

Yeah. It’s the nn_model part (5.2). Cost funtion worked perfectly individually.

So, in those cases as I suggest previously, you have to be sure about the parameters dimensions which are A2 and Y. Apply print statement so that you can narrow down your debugging search.

can i post github link for you to check?

Y.shape = (1,400)
np.log(A2).shape = (1,3)
If it workes on Compute cost part i dont understand why it doesnt work here

Here’s whole error message if it helps

ValueError Traceback (most recent call last)
in
1 # Build a model with a n_h-dimensional hidden layer
----> 2 parameters = nn_model(X, Y, n_h, num_iterations = 10000, print_cost=True)
3
4 # Plot the decision boundary
5 plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y)

in nn_model(X, Y, n_h, num_iterations, print_cost)
45 # YOUR CODE STARTS HERE
46 A2, cache = forward_propagation(t_X, parameters)
—> 47 cost = compute_cost(A2,Y)
48 grads = backward_propagation(parameters, cache, t_X, t_Y)

in compute_cost(A2, Y)
22 # YOUR CODE STARTS HERE
23 logprobs = None
—> 24 logprobs=np.multiply(np.log(A2),Y) + np.multiply(np.log(1-A2),1-Y)
25 cost = None
26 cost = (-1/m)*np.sum(logprobs)

ValueError: operands could not be broadcast together with shapes (1,3) (1,400)

That would be violation of honor code. Hence, unfortunately, I could not do this. What I really want is to give you an intuation about a debugging skills.