I think it is much faster if you calculate the new output in one loop, instead of three.