我在 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 理解,我愿意接受建议。它大概看起来像这样:。我只是不熟悉我的案例的等效语法。一个好的参考就足够了。谢谢。