So for the graded lab assignment, I have created my compute_cost function, but realized that the original code provided was not summing the total_cost function anywhere, and was thus only an array. To resolve this, I used return np.sum(total_cost) rather than just total_cost.

While this ensures that the output of my compute_cost function is a value and not an array, I am running into an assertion error

The test expects the cost function to return 0, indicating a perfect prediction (when the model’s predictions are correct). However, to our surprise, the cost returned is 28.0 , a far cry from perfect.

Reasons.

Incorrect Model Parameters (initial_w and initial_b) or Incorrect Implementation of the Cost Function, the compute cost might not calculate the cost as expected. The cost should be close to 0 if the predictions perfectly match the labels (y), but in your case, it’s returning 28.0, suggesting either incorrect predictions or cost calculation

The second link provided in my previous comments gives you right code for the cost calculation for ith iteration where you mentioned the code without the i

you used (f_wb - y) * 2 where as
it should be (f_wb -y[i]) ** 2

Thank you @Deepti_Prasad. I get it now that I wasn’t slicing the target variable with [i], thus getting a tuple in the result rather than a value. Once I change, I get an Assertion Error on case 2