Using numpy vectorization speeds it up a lot...