我用 Fortran 写出了一个矩阵,如下所示:
real(kind=kind(0.0d0)), dimension(256,256,256) :: dense
[...CALCULATION...]
inquire(iolength=reclen)dense
open(unit=8,file=fname,&
form='unformatted',access='direct',recl=reclen)
write(unit=8,rec=1)dense(:,:,:)
close(unit=8)
我想把这个读回 Python 中。我所看到的一切都是 2D NxN 数组而不是 3D 数组。在 Matlab 中我可以将其读作:
fid = fopen(nfilename,'rb');
mesh_raw = fread(fid,ndim*ndim*ndim,'double');
fclose(fid);
mesh_reshape = reshape(mesh_raw,[ndim ndim ndim]);
我只需要 Python 中的等效工具 - 大概有类似的加载/重塑工具可用。如果有一种更友好、紧凑的方式来写出来供 Python 理解,我愿意接受建议。它大概会看起来有些东西this https://stackoverflow.com/questions/13728591/simple-reading-of-fortran-binary-data-not-so-simple-in-python: 。我只是不熟悉我的情况的等效语法。一个好的参考就足够了。谢谢。