and to calculate ‘db’ using the formula: db = np.sum(A-Y)/m

Whether I use np.sum in the ‘cost’ function or not my all tests are passed but if I don’t use np.sum in db function it throws an error as ‘assert type(grads[“db”]) == np.float64’

I want to know why db can’t be used without np.sum and if it is necessary then how cost function is not giving an error?

This is one of the lines in the test cases, which you also pointed out, assert type(grads["db"]) == np.float64

Over here you can see that the ‘type’ of db is being checked to make sure it is np.float64. But there’s no check on the ‘type’ of cost. I’m guessing using np.sum changes the the type to float64. And since there’s no check on the type of ‘cost’, it doesn’t matter what it ends up being.

Thanks for the clarification!
In both cases ‘cost’ is returning an ‘ndarray’ while ‘db’ returns ‘ndarray’ if np.sum is not used and ‘float64’ if np.sum is used.