MLS C1 W2 Programming Assignment Error

I have already compiled both of the exercises, but I am being unable to call the gradient descent function and instead being displayed with this error message “only size-1 arrays can be converted to Python scalars”.

I would really appreciate any help and guidance.

Hello @Wanhar_Aziz,

Here is how we can deal with an error like that.

  1. Google the error message “only size-1 arrays can be converted to python scalars
  2. Check out a few relevant links. Usually links of stackoverflow.
  3. One of the stackoverflow answers says the error is there because

when the function expects a single value but you pass an array instead

  1. In the error traceback you posted, the only conversion is the function float
  2. Therefore, it is likely that your J_history[-1] is an array instead of an expected scalar.
  3. You need to make sure you only append scalar value to J_history which should be part of your exercise.

The above debugging steps is a pretty common skill and being familiar with it will help your future work a lot!

Good luck debugging!