Also the mode4 = mode4[1:, :]...

Additionally this seems just to handle the edge cases. Think about it again, you should be easily able to implement this directly in Cython, so we can avoid the final slicing...