我用ndarray.tobytes(order='F')
在Python中保存了一个矩阵。
f_mat = open('mat.dat', 'wb')
f_mat.write(matrix.tobytes('F'))
f_mat.close()
有没有快速的方法在Fortran中阅读它,还是我应该循环并找出元素的顺序?
答案 0 :(得分:2)
如果你知道大小(n
时间m
)和数组的类型并相应地声明它:
!just an example
real(c_double), allocatable :: mat(:,:)
allocate(mat(n,m))
应该只是
open(newunit = u, file='mat.dat', access='stream', form='unformatted', status='old', action='read')
read(u) mat
close(u)
open
之后access='stream'
的参数是可选的。