Rewrote looping over dA_layers to be more pythonic