[Numpy-discussion] bug with with fill_values in masked arrays?
Matt Knox
mattknox_ca@hotmail....
Wed Mar 19 18:47:37 CDT 2008
>
> OK, my specific problem with masked arrays is as follows:
>
> >>> a = numpy.array([1,numpy.nan,2])
> >>> aa = numpy.ma.masked_where(numpy.isnan(a),a)
> >>> aa
> array(data =
> [ 1.00000000e+00 1.00000000e+20 2.00000000e+00],
> mask =
> [False True False],
> fill_value=1e+020)
>
> >>> numpy.ma.set_fill_value(aa,0)
> >>> aa
> array(data =
> [ 1. 0. 2.],
> mask =
> [False True False],
> fill_value=0)
>
> OK, so this looks like I want it to, however:
>
> >>> [v for v in aa]
> [1.0, array(data =
> 999999,
> mask =
> True,
> fill_value=999999)
> , 2.0]
>
> Two questions:
>
> 1. why am I not getting my NaN's back?
when iterating over a masked array, you get the "ma.masked" constant for
elements that were masked (same as what you would get if you indexed the masked
array at that element). If you are referring specifically to the .data portion
of the array... it looks like the latest version of the numpy.ma sub-module
preserves nan's in the data portion of the masked array, but the old version
perhaps doesn't based on the output you are showing.
>
> 2. why is the wrong fill value being used here?
the second element in the array iteration here is actually the numpy.ma.masked
constant, which always has the same fill value (which I guess is 999999). This
is independent of the fill value for your specific array.
- Matt
More information about the Numpy-discussion
mailing list