Converting Fortran array to numpy array

Viewed 249

I am in the process of converting a Fortran 90 code to python. The Fortran code includes multidimensional array like:

integer fvpair(3,12,2)
integer jpair(3,2)
real*8 aread(3,12)

I wonder if the following numpy array are correct equivalent, assuming zero initialization:

fvpair = np.array([[np.zeros(3)],[np.zeros(12)],[np.zeros(2)]])
jpair = np.array([[np.zeros(3)],[np.zeros(2)]])
aread = np.array([[np.zeros(3)],[np.zeros(12)]])
1 Answers

If you want to preserve the original Fortran array storage order (column-major), do not forget to pass the order='F' flag!

fvpair = np.zeros((3,12,2), dtype=int, order='F')
jpair = np.zeros((3,2), dtype=int, order='F')
aread = np.zeros((3,2), dtype=float64, order='F')
Related