[Numpy-discussion] masked arrays and record arrays
Fri Jun 15 12:13:34 CDT 2007
On Thursday 14 June 2007 09:19:06 John Hunter wrote:
> On 6/13/07, Pierre GM <firstname.lastname@example.org> 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?
Sorry for the delayed answer: I had to fix a couple of minor bugs here and
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 = MA.masked
"Set the mask on a field"
mr.ffloat[-1] = MA.masked
Another example is provided in the mrecords.py file.
Please give it a try, I'm looking forward to your feedback.
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.
More information about the Numpy-discussion