I am trying to output a 4D numpy float array to a plaintext file using numpy.savetxt
However numpy gives an error saying that a float argument is required when I try to pass this array. Nevertheless the numpy doc specifies that the argument to be passed should just be array like… NOT that it should be of max rank 2. The only way I can make it work is by reshaping the data to 2D (and this is actually not always practical for data organisation reasons)
Is there way around this? Or must one necessarily reshape the numpy array to 2D?
I was expecting to be able to read the data in fortran like column-by-column style (working up through the dimensions).
Are there other possibilities? Note that I do not want to use the npy format since I seek compatibility with another program which needs plaintext format.
A different approach is to save the array as a simple list of numbers (the flat version of the array) and save along it the information about its shape.
The problem about multidimensional arrays is that it’s not that simple to move them from program to program even in text format.
you can do something like this:
and use the information on the size inclued in the filename to restore the initial shape