[Numpy-discussion] Masking entries in structured arrays

Marcin Wlodarczak mwlodarczak at uni-bielefeld.de
Fri Jul 15 05:28:42 EDT 2011


On 14.07.2011 12:36, Christopher Jordan-Squire wrote:
>> > I was wondering whether it is possible to mask specific entries in a
>> > structured array. If I try to do the following:
>> >
>> > x = ma.masked_array([(2, 1.), (8, 2.)], dtype=[('a',int), ('b', float)])
>> > x_masked = ma.masked_equal(x, 2)
>> >
>> > I get "AttributeError: 'NotImplementedType' object has no attribute
>> > 'ndim'", which actually makes sense since x.shape returns (2,). I really
>> > can't think of any way around this problem.
>> >
>> >
> It's not terribly satisfying, but you can iterate over the field names.
> for field in x.dtype.names:
>     x[field] = np.ma.masked_equal(x[field],2)

Thanks. It's really a pity it's not possible to use masked_equal
directly though.

Best,
M.



More information about the NumPy-Discussion mailing list