I'm writing an application that reads an ascii file with fortran-ordered arrays, modifies values, then writes that data back out (in fortran order) in ascii. What is the correct way to read this array into numpy, denote the array is in fortran order, then write the data back out in fortran order?
Assume I have a file with the following ascii text:
0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0
These numbers represent a 2x2x2 array written in fortran order.
The ascii format is a bit more complicated than above. However, suffice it to say the format is not really well suited for using any of the automatic numpy ascii loaders like numpy.loadtxt, etc.
I'm executing a line similar to the following to create the array:
x = numpy.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], order='F')
I know this is in-efficient and does a lot of extra data copying, etc. I'm more worried about the ordering though.
So, at this point x is ordered in memory like a fortran array, I think. Now, when I export this array should I use numpy.nditer(x, order='F')?
xis already ordered like a Fortran array,orderis not needed innditer(which, by default, iterates in memory order).