pythonnumpycontiguous

Check if numpy array is contiguous?


How can I find out if a n-dimensional numpy array Arr is contiguous in C-style or Fortran-style?


Solution

  • The numpy documentation states that it is possible to check whether an array is C-contiguous or Fortran-contiguous via the attribute flags:

    Arr.flags['C_CONTIGUOUS']
    Arr.flags['F_CONTIGUOUS']
    

    These attributes return a boolean indicating which of the two cases is true.