Woltan Woltan - 1 month ago 14
Python Question

How to force numpy array order to fortran style?

I am using quite a lot of fortran libraries to do some mathematical computation. So all the arrays in numpy need to be Fortran-contiguous.

Currently I accomplish this with numpy.asfortranarray().

My questions are:


  1. Is this a fast way of telling numpy that the array should be stored in fortran style or is there a faster one?

  2. Is there the possibility to set some numpy flag, so that every array that is created is in fortran style?


Answer

Use optional argument order='F' (default 'C'), when generating numpy.array objects. This is the way I do it, probably does the same thing that you are doing. About number 2, I am not aware of setting default order, but it's easy enough to just include order optional argument when generating arrays.