A reimplementation of MaskedArray

Michael Sorich michael.sorich at gmail.com
Mon Oct 16 21:08:50 CDT 2006


Does this new MA class allow masking of rearray like arrays? The numpy
(1.0b5) version does not seem to. e.g.

from numpy import *

desc = [('name','S30'),('age',int8),('weight',float32)]
a = array([('Bill',31,260.0),('Fred', 15, 145.0)], dtype=desc)
print a[0]
print a['name']

a2 = ma.array([('Bill',31,260.0),('Fred', 15, 145.0)], dtype=desc,
mask=ma.nomask)
print a2[0]
print a2['name']

a3 = ma.array([('Bill',31,260.0),('Fred', 15, 145.0)], dtype=desc,
mask=[[True,False,False],[False,False, False]])
print a3[0]
print a3['name']

-- output

('Bill', 31, 260.0)
[Bill Fred]
('Bill', 31, 260.0)
[Bill Fred]
Traceback (most recent call last):
  File "D:\eclipse\Table\scripts\testrecarray.py", line 12, in ?
    a3 = ma.array([('Bill',31,260.0),('Fred', 15, 145.0)], dtype=desc,
mask=[[True,False,False],[False,False, False]])
  File "C:\Python23\Lib\site-packages\numpy\core\ma.py", line 592, in __init__
    raise MAError, "Mask and data not compatible."
numpy.core.ma.MAError: Mask and data not compatible.




On 10/16/06, Pierre GM <pgmdevlist at mailcan.com> wrote:
> Folks,
> I just posted on the scipy/developers zone wiki
> (http://projects.scipy.org/scipy/numpy/wiki/MaskedArray) a reimplementation
> of the masked_array mopdule, motivated by some problems I ran into while
> subclassing MaskedArray.
>
> The main differences with the initial numpy.core.ma package are that
> MaskedArray is now a subclass of ndarray and that the _data section can now
> be any subclass of ndarray (well, it should work in most cases, some tweaking
> might required here and there). Apart from a couple of issues listed below,
> the behavior of the new MaskedArray class reproduces the old one. It is quite
> likely to be significantly slower, though: I was more interested in a clear
> organization than in performance, so I tended to use wrappers liberally. I'm
> sure we can improve that rather easily.
>
> The new module, along with a test suite and some utilities, are available
> here:
> http://projects.scipy.org/scipy/numpy/attachment/wiki/MaskedArray/maskedarray.py
> http://projects.scipy.org/scipy/numpy/attachment/wiki/MaskedArray/masked_testutils.py
> http://projects.scipy.org/scipy/numpy/attachment/wiki/MaskedArray/test_maskedarray.py
>
> Please note that it's still a work in progress (even if it seems to work quite
> OK when I use it). Suggestions, comments, improvements and general feedback
> are more than welcome !
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list