On *exercise 1* of *section 5 - L2 Regularization* I tried to use list comprehension to calculate the value of `L2_regularization_cost`

, but got the error `AssertionError: Not all tests were passed for compute_cost_with_regularization. Check your equations and avoid using global variables inside the function.`

On the other hand, if I calculate `np.sum(np.square(Wl))`

for each layer and then sum all 3, I pass the test. I checked the values and they match doing both ways. I also tried coping the `parameters`

argument and assigning it to a new variable instead of using it directly on the iteration, but still kept getting the same error. Any idea why? tks

I managed to figure out my mistake this morning. I was iterating through the whole `parameters`

dictionary. I forgot about the parameter `b`

, so I was summing them into L2. An if/else in the iteration, assigning 0 to the b parameters, solved the problem.

1 Like