[Numpy-discussion] masked arrays and record arrays
Pierre GM
pgmdevlist at gmail.com
Fri Jun 15 13:13:34 EDT 2007
On Thursday 14 June 2007 09:19:06 John Hunter wrote:
> On 6/13/07, Pierre GM <pgmdevlist at gmail.com> wrote:
> > Have you tried mrecords, in the alternative maskedarray package available
> > on the scipy SVN ?
> I would be happy to try this out -- do you happen to have an example
> that shows how to set the masks on the individual fields?
>
> JDH
John,
Sorry for the delayed answer: I had to fix a couple of minor bugs here and
there.
The easiest would be something along those lines:
#------------------
import numpy as N
import maskedarray as MA
import maskedarray.mrecords as MR
x = [(1.,10.,'a'),(2.,20,'b'),(3.14,30,'c'),(5.55,40,'d')]
desc = [('ffloat', N.float_), ('fint', N.int_), ('fstr', 'S10')]
mr = MR.fromrecords(x,dtype=desc)
"Set the mask on a record"
mr[0] = MA.masked
"Set the mask on a field"
mr.ffloat[-1] = MA.masked
print mr
#------------------
Another example is provided in the mrecords.py file.
Please give it a try, I'm looking forward to your feedback.
Pierre
PS:
<pushing_product>
If you're working w/ datetime objects, you might also be interested in the
TimeSeries package, also available on the SVN. The tmulti subpackage defines
a MultiTimeSeries object, which is a mixture of TimeSeries and MaskedRecords.
This is just a rough prototype, but that could be a start.
</pushing_product>
More information about the NumPy-Discussion
mailing list