我得到一个我觉得难以理解的堆栈跟踪:
screwed_up_code.py in atleast_4d(arr)
28 def atleast_4d(arr):
29 stshape = arr.shape
30 while len(stshape)<4: stshape+=(1,)
31 print arr.shape, stshape
---> 32 return arr.reshape(stshape)
/usr/lib/python2.7/dist-packages/numpy/core/memmap.pyc in __array_finalize__(self, obj)
255 if hasattr(obj, '_mmap'):
256 self._mmap = obj._mmap
--> 257 self.filename = obj.filename
258 self.offset = obj.offset
259 self.mode = obj.mode
AttributeError: 'memmap' object has no attribute 'filename'
如果你想知道arr.shape = (192, 384, 6)
和stshape = (192, 384, 6, 1)
更新
正如 NPE 所建议的,我查看了类似听起来 AttributeError 的错误报告。那里的一张海报将其归咎于由于ndarrays的酸洗而丢失的属性。我确实在酸洗数组,当像这样重新激活加载的数组时:
newarr = numpy.ndarray(pickled_array)
pickled_array = newarr # use the recreated instead of the pickled arr
我收到警告而不是异常,并且我的代码运行:
Exception AttributeError: AttributeError("'NoneType' object has no attribute 'tell'",) in ignored
Exception AttributeError: AttributeError("'NoneType' object has no attribute 'tell'",) in ignored
Exception AttributeError: AttributeError("'NoneType' object has no attribute 'tell'",) in <bound method memmap.__del__ of memmap([ 85389.2734375, 125935.75 , 173624.09375 , 272958.78125 ,
305687.65625 , 433026.3125 ], dtype=float32)> ignored
我很高兴我的代码可以运行,并且暂时将其保留。