Is your regularization term in the loop for calculating the cost function?
The regularization terms only need to be calculated once and added at the end.

Thank you for your answer. The issue was that the regularization term was placed inside of a loop. This is my final code and now everything works fine:

~ {mentor edit: removed code / solution to assignment} ~

Wow, it took me a long time to figure this out as well! Perhaps the description cell 4.1 should include some extra parentheses in the equation for clarity?