Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does a memmap need a filename when I try to reshape a numpy array?
    primarykey
    data
    text
    <p>I am getting a stacktrace that I find difficult to understand:</p> <pre><code>screwed_up_code.py in atleast_4d(arr) 28 def atleast_4d(arr): 29 stshape = arr.shape 30 while len(stshape)&lt;4: stshape+=(1,) 31 print arr.shape, stshape ---&gt; 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 --&gt; 257 self.filename = obj.filename 258 self.offset = obj.offset 259 self.mode = obj.mode AttributeError: 'memmap' object has no attribute 'filename' </code></pre> <p>In case you wonder <code>arr.shape = (192, 384, 6)</code> and <code>stshape = (192, 384, 6, 1)</code></p> <hr> <p><strong>UPDATE</strong></p> <p>As suggested by NPE , I looked into <a href="http://projects.scipy.org/numpy/ticket/1809" rel="nofollow">the bug report of a similar sounding AttributeError</a>. A poster there blamed it on attributes getting lost due to pickling of ndarrays. I am indeed pickling arrays and when re-vitalize the loaded arrays like so:</p> <pre><code>newarr = numpy.ndarray(pickled_array) pickled_array = newarr # use the recreated instead of the pickled arr </code></pre> <p>I get warnings instead of Exceptions and my code runs:</p> <pre><code>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 &lt;bound method memmap.__del__ of memmap([ 85389.2734375, 125935.75 , 173624.09375 , 272958.78125 , 305687.65625 , 433026.3125 ], dtype=float32)&gt; ignored </code></pre> <p>I am happy enough that my code runs and will leave it at that for the moment.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload