Course 1, week 4 , Assignment 2- Error in 2 layer model

While executing the 2 layer model in the 2nd assignment, I end up getting the following error message. When I searched about this in the community, I got to know many people are getting this error. Upon reading the solution provided by the mentors to them, I tried to figure it out myself but it was futile. I am a screenshot of the error. Please help me out in this.

Here is my output:

Cost after iteration 1: 0.6926114346158595
Cost after first iteration: 0.693049735659989
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 2: 0.6524135179683452
 All tests passed.

The cost values you show mostly look right, but notice that on the second line it shows the output as a 2D array with one element, instead of a scalar value. Did you perhaps “hand import” your own functions from the “Step by Step” exercise? If so, that was a mistake: they provide you with the functions as an import file.

If you look at the “Cost after first iteration”, it is [[0.69304974]]. This must be “cost”, and its shape is (1,1). In a previous assignment (and also in a helper utility), it removes axes of length one by np.squeeze. So, the expected cost is actually inside a square bracket, 0.69304974.
There are two possibilities.

  1. As Paul pointed, you have a local copy of compute_cost() which does not apply np.squeeze() for cost.
  2. Or, you calculated cost in here, since it is just a one line code. :slight_smile: In this case, most likely there is no np.squeeze(). As guided, please use a helper function instead.

In any cases, please check your “cost” calculation.