TypeError: unsupported format string passed to numpy.ndarray.__format__

Hi, @Mohamed.Hesham.nour

the function compute_cost should return a scalar value float but in your case here it’s returning a NumPy array.

this what cause you an error. check the function implementation again. I believe you just miss to sum the values.



I understand your point but i don’t know how to solve this issue :sweat_smile:


Please, do not post any if your code as it’s against the Student Honor code.

i deleted the photo, how can i solve this problem?

The problem is that your function is returning an array not a scalar value.
try using indexing at your return like

return total_cost[0]

and see it solves your problem or not.

it returned float value, but it clashed in case 2


can please tell me the shape of the output without using indexing

<class ‘numpy.ndarray’>
=if i used return total_cost[0]
<class ‘numpy.float64’>

Hello @Mohamed.Hesham.nour,

You have less than 10 lines of code, so after each line, I suggest you to add a new line to print the content of the assigned variable in the previous line. Below is an example:

Screenshot from 2022-11-02 18-59-29
Source: general code debugging tips

As soon as you see your printed variable being an array or a list, there is the problem.