by numpy alonewriting code in cfortranor especially cython (see bit more on this belowmay be in order personally use cython (own work as an easy way to get -like performance with minimal development the importance of contiguous memory while the full extent of this topic is bit outside the scope of this bookin some applications the memory layout of an array can significantly affect the speed of computations this is based partly on performance differences having to do with the cache hierarchy of the cpuoperations accessing contiguous blocks of memory (for examplesumming the rows of order arraywill generally be the fastest because the memory subsystem will buffer the appropriate blocks of memory into the ultrafast or cpu cache alsocertain code paths inside numpy' codebase have been optimized for the contiguous case in which generic strided memory access can be avoided to say that an array' memory layout is contiguous means that the elements are stored in memory in the order that they appear in the array with respect to fortran (column majoror (row majorordering by defaultnumpy arrays are created as -contiguous or just simply contiguous column major arraysuch as the transpose of ccontiguous arrayis thus said to be fortran-contiguous these properties can be explicitly checked via the flags attribute on the ndarrayin [ ]arr_c np ones(( )order=' 'in [ ]arr_f np ones(( )order=' 'in [ ]arr_c flags out[ ]c_contiguous true f_contiguous false owndata true writeable true aligned true updateifcopy false in [ ]arr_f flags out[ ]c_contiguous false f_contiguous true owndata true writeable true aligned true updateifcopy false in [ ]arr_f flags f_contiguous out[ ]true in this examplesumming the rows of these arrays shouldin theorybe faster for arr_c than arr_f since the rows are contiguous in memory here check for sure using %timeit in ipythonin [ ]%timeit arr_c sum( loopsbest of ms per loop in [ ]%timeit arr_f sum( loopsbest of ms per loop performance tips www it-ebooks info