user308827
user308827

Reputation: 21971

Multiplying masked arrays changes fill value in numpy

I have 2 masked arrays, both of the form:

masked_array(data =
 [[-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 ..., 
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]],
             mask =
 [[ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 ..., 
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]],
       fill_value = -9999.0)

When I multiply them, the fill_value changes to fill_value = 1e+20

Why is that happening? and how can I retain the previous fill value? This is how i am multpliying them:

array_a * array_b

Upvotes: 3

Views: 1333

Answers (1)

ali_m
ali_m

Reputation: 74172

The behaviour you're referring to was introduced by this commit from October 2013, which found its way into releases from v1.10.0 onwards.

I'm not 100% sure whether or not it should be considered a bug. It seems unreasonable to me, but the documentation doesn't seem to specify what should happen to the fill value when a ufunc is applied to it. There are a couple of related open issues on the numpy GitHub tracker.

Upvotes: 1

Related Questions