Hi, I just noticed this and found it surprising: In [8]: from numpy import ma In [9]: a = ma.array([1,2,3,4],mask=[False,False,True,False],fill_value=0) In [10]: a Out[10]: masked_array(data = [1 2 -- 4], mask = [False False True False], fill_value=0) In [11]: a[2] Out[11]: masked_array(data = --, mask = True, fill_value=1e+20) In [12]: np.__version__ Out[12]: '1.1.0' Is there a reason that the fill_value isn't inherited from the parent array? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma
Ryan May wrote:
Hi,
I just noticed this and found it surprising:
In [8]: from numpy import ma
In [9]: a = ma.array([1,2,3,4],mask=[False,False,True,False],fill_value=0)
In [10]: a Out[10]: masked_array(data = [1 2 -- 4], mask = [False False True False], fill_value=0)
In [11]: a[2] Out[11]: masked_array(data = --, mask = True, fill_value=1e+20)
In [12]: np.__version__ Out[12]: '1.1.0'
Is there a reason that the fill_value isn't inherited from the parent array?
There was a thread about this a couple months ago, and Pierre GM explained it. I think the point was that indexing is giving you a new masked scalar, which is therefore taking the default mask value of the type. I don't see it as a problem; you can always specify the fill value explicitly when you need to. Eric
Ryan
Eric Firing wrote:
Ryan May wrote:
Hi,
I just noticed this and found it surprising:
In [8]: from numpy import ma
In [9]: a = ma.array([1,2,3,4],mask=[False,False,True,False],fill_value=0)
In [10]: a Out[10]: masked_array(data = [1 2 -- 4], mask = [False False True False], fill_value=0)
In [11]: a[2] Out[11]: masked_array(data = --, mask = True, fill_value=1e+20)
In [12]: np.__version__ Out[12]: '1.1.0'
Is there a reason that the fill_value isn't inherited from the parent array?
There was a thread about this a couple months ago, and Pierre GM explained it. I think the point was that indexing is giving you a new masked scalar, which is therefore taking the default mask value of the type. I don't see it as a problem; you can always specify the fill value explicitly when you need to.
I thought it sounded familiar. You're right, it's not a big problem, it just seemed unintuitive. Thanks for the explaination. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma
On Saturday 19 July 2008 18:41:22 Ryan May wrote:
There was a thread about this a couple months ago, and Pierre GM explained it. I think the point was that indexing is giving you a new masked scalar, which is therefore taking the default mask value of the type. I don't see it as a problem; you can always specify the fill value explicitly when you need to.
Actually, in that example, a[2] is THE masked scalar: that's a constant initialized when you import numpy.ma, it doesn't depend on the type.
I thought it sounded familiar. You're right, it's not a big problem, it just seemed unintuitive. Thanks for the explaination.
It is in a way, but it's needed for compatibility with older code. That way, you can test whether a value is masked by using: a[2] is masked Yeah, you could also check whether the mask if not nomask and whether the mask at this particular element is True, but it's a bit longer.
participants (3)
-
Eric Firing
-
Pierre GM
-
Ryan May