[Numpy-discussion] .transpose() of memmap array fails to close()

Glen W. Mabey Glen.Mabey at swri.org
Thu Jun 7 17:46:20 EDT 2007


Hello,

When assigning a variable that is the transpose() of a memmap array, the
._mmap member doesn't get copied, I guess:

In [1]:import numpy

In [2]:amemmap = numpy.memmap( '/tmp/afile', dtype=numpy.float32, shape=(4,5), mode='w+' )

In [3]:bmemmap = amemmap.transpose()

In [4]:bmemmap.close()
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'>        Traceback (most recent call last)

/home/gmabey/src/R9619_dev_acqlibweb/Projects/R9619_NChannelDetection/NED/<ipython console> in <module>()

/usr/local/stow/numpy-20070605_svn-py2.5/lib/python2.5/site-packages/numpy/core/memmap.py
in close(self)
     86 
     87     def close(self):
---> 88         self._mmap.close()
     89 
     90     def __del__(self):

<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'close'
> /usr/local/stow/numpy-20070605_svn-py2.5/lib/python2.5/site-packages/numpy/core/memmap.py(88)close()
     87     def close(self):
---> 88         self._mmap.close()
     89 




This is an issue when the data is accessed in an order that is different
from how it is stored on disk, as:

bmemmap = numpy.memmap( '/tmp/afile', dtype=numpy.float32, shape=(4,5), mode='w+' ).transpose()

So the object that was originally produced not accessible.  I imagine
there is some better way to indicate order of dimensions, but
regardless, doing

In [4]:bmemmap._mmap = amemmap._mmap

is a hack workaround.

Best regards,
Glen Mabey



More information about the NumPy-Discussion mailing list