more efficient cython loop