OK @Thrasso00
I think that the error in your code isn’t from the wrong implementation but it’s because the round up of data types(the size of data types) so that make sure in your implementation, you didn’t compute the cost and put the output in variable, and after that you doing sum over this variable, In the other words use the accumulation variable directly like ( += )
J += ...... * np.square((............... - ..... ))
That would preserve the small fractions in your calculations ,
Also Make sure that you use regularisation
Best Regards,
Abdelrahman