speed up

pre-allocated in numpy array and reduced loop checking.