I’m trying to extract the non-masked rows from an Astropy Table. From the Astropy Table documentation, I can get the indices of the masked, but how do I get the inverse?
To get the indices of masked elements, use an expression like: >>> t['a'].mask.nonzero()
I think what you want is t[~t['a'].mask] to get a new table where rows with masked elements in 'a' have been removed:
In [29]: t
Out[29]:
<Table masked=True length=2>
a b
int64 int64
----- -----
1 --
-- 4
In [30]: t[~t['a'].mask]
Out[30]:
<Table masked=True length=1>
a b
int64 int64
----- -----
1 --
Pandas has powerful ways to do selection on columns, but I’m not sure there is really a point in reimplementing that in Astropy. In Astropy columns are simple Numpy arrays, so most simple things can be in a slightly more verbose way (compared to Pandas) with simple Numpy selections. And for more advanced usage it’s easy to convert the table to Pandas (t.to_pandas()).