Compeute cost error

I Completed this week and submitted it , but when i run the pre implemented model in gave error in compute_cost function

In your compute_cost() function, either a3 or Y is the wrong shape. They should be the same.

but I didn’t compute them in is assignment

Then the values you’re passing to compute_cost() must have come from somewhere.


As Tom points out, the problem is not in the compute_cost function, it is that you passed it mismatching arguments. A completely correct function can still throw errors if you pass it bad arguments. So now you need to work backwards from the point of the error to figure out how that could happen.

I added the following cell right after the cell that loads train_X and train_Y:

print(f"train_X.shape {train_X.shape}")
print(f"train_Y.shape {train_Y.shape}")
m = train_X.shape[1]
print(f"m = {m}\nm mod 64 = {m % 64}")

Here’s what that shows:

train_X.shape (2, 300)
train_Y.shape (1, 300)
m = 300
m mod 64 = 44

So it looks like there is some error in your code about handling minibatches versus the full batch and the error seems to happen only on the last minibatch. The number of elements in the Y value is incorrect in that case and is the whole batch. That should at least give some clues about where to look for the problem. Note that the minibatch_Y value being used there is the return value from your random_mini_batches function. Did that pass all the test cases?

I didn’t find it

Please check your personal messages for instructions.

1 Like

think you so match