在相同文件上初始化内存映射会产生不同的数组

时间:2018-06-26 01:14:05

标签: python numpy

我正在翻译一些算法,并通过比较输出来检查我的工作。我有IDL创建的.img文件和Python创建的.img文件。这两个输出按位相同,但是当我打开一个内存映射以继续处理时,Python文件丢失了一些数据。

>>> mm = np.memmap("X:/eordentl/Processing Algorithms/processed_data_py/
        C5704B-00045Z-03_verytop_2017_08_17_03_28_29/
        C5704B-00045Z-03_verytop_2017_08_17_03_28_29_SWIRcalib.img", 
        dtype="float32", mode="r", offset=0, shape=(333,320,285))
>>> mm[0]
memmap([[ 0.        ,  0.        ,  0.        , ...,  0.        ,
          0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        , ...,  0.        ,
          0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        , ...,  0.        ,
          0.        ,  0.        ],
        ...,
        [ 0.3388325 ,  0.30027774,  0.32364482, ...,  0.40399274,
          0.42492244,  0.41838124],
        [ 0.28071803,  0.30334   ,  0.32874447, ...,  0.10009208,
          0.10556249,  0.05749646],
        [ 0.09928307,  0.1659135 ,  0.36206895, ...,  0.00572116,
         -0.00990769,  0.00214016]], dtype=float32)
>>> mm2=np.memmap("X:/eordentl/Processing Algorithms/processed_data_idl/
        C5704B-00045Z-03_verytop_2017_08_17_03_28_29_SWIRcalib.img", 
        dtype="float32", mode="r", offset=0, shape=(333,320,285))
>>> mm2[0]
memmap([[ 0.01608727,  0.03300966,  0.04274924, ...,  0.07621645,
          0.07274907,  0.07459512],
        [ 0.06294538,  0.07551169,  0.07973923, ...,  0.42498964,
          0.38354877,  0.396222  ],
        [ 0.34490117,  0.3083234 ,  0.27291125, ...,  0.32263884,
          0.31246758,  0.3155154 ],
        ...,
        [ 0.3388325 ,  0.30027774,  0.32364482, ...,  0.40399274,
          0.42492244,  0.41838124],
        [ 0.28071803,  0.30334   ,  0.32874447, ...,  0.10009208,
          0.10556249,  0.05749646],
        [ 0.09928307,  0.1659135 ,  0.36206895, ...,  0.00572116,
         -0.00990769,  0.00214016]], dtype=float32)
>>> import filecmp
>>> filecmp.cmp("X:/eordentl/Processing Algorithms/processed_data_py/C5704B-00045Z-03_verytop_2017_08_17_03_28_29/C5704B-00045Z-03_verytop_2017_08_17_03_28_29_SWIRcalib.img","X:/eordentl/Processing Algorithms/processed_data_idl/C5704B-00045Z-03_verytop_2017_08_17_03_28_29_SWIRcalib.img")
True

我非常困惑。这些不是唯一的区别,请参见

>>> np.count_nonzero(mm2-mm)
109685

尽管该数字更可能是由于浮点错误引起的。

鉴于文件一点一点相同(通过Windows cmd上的FC / b验证),是什么引起了差异,我该如何解决?

0 个答案:

没有答案