[Numpy-discussion] numpy.var fails on memmap

Bartosz Telenczuk b.telenczuk at biologie.hu-berlin.de
Tue Feb 1 16:59:24 EST 2011


Hi,

numpy.var on a memory mapped array returns a 0-d memmap object instead of a scalar (like with numpy arrays):

>>> import numpy as np
>>> fp = np.memmap('test.mm', dtype='float32', mode='w+', shape=(10,))
>>> fp[:] = np.random.rand(10)
>>> fp_var= np.var(fp)
>>> print type(fp_var)
<class 'numpy.core.memmap.memmap'>
>>> print fp_var.ndim
0

Moreover, the obtained object is missing 'filename' attribute, so that it can not be reused in further calculations:

>>> fp_std = np.sqrt(fp_var)
...
AttributeError: 'memmap' object has no attribute 'filename'

I can produce this bug in numpy 1.5.1 with python2.6 (from macports).

Cheers,

Bartosz


Institute for Theoretical Biology
Humboldt University of Berlin
Germany
http://neuroscience.telenczuk.pl




More information about the NumPy-Discussion mailing list