cleanup: substitute for loops with numpy functions