In [16]:
from astropy.table import Table, Column, hstack
import numpy as np
In [28]:
arr = np.arange(15).reshape(5, 3)
print(arr)
t = Table(arr, names=('a', 'b', 'c'), meta={'keywords': {'key1': 'val1'}})
print(t)
aa = Column(np.arange(5), name='aa')
print(aa)
t.add_column(aa, index=0) # Insert before the first table column
print(t)
bb = Column(np.arange(5))
t.add_column(bb, name='bb') # Append unnamed column to the table with 'bb' as name
print(t)
t2 = Table(np.arange(25).reshape(5, 5), names=('e', 'f', 'g', 'h', 'i'))
print(t2)
t.add_columns(t2.columns.values())
print(t)
print(t2)
In [2]:
t2.columns['e', 'f'].values()
Out[2]:
In [3]:
x = t['a', 'b', 'c']
x
Out[3]:
In [4]:
t
Out[4]:
In [5]:
y = t.remove_column('a')
y
In [6]:
t
Out[6]:
In [7]:
x = t
In [8]:
x
Out[8]:
In [9]:
t.remove_column('f')
In [10]:
x
Out[10]:
In [11]:
y = x[[True, False, True, False, True]]
In [12]:
y
Out[12]:
In [13]:
x
Out[13]:
In [14]:
t1 = Table.read("""a b c
1 foo 1.4
2 bar 2.1
3 baz 2.8""", format='ascii')
t2 = Table.read("""d e
ham eggs
spam toast""", format='ascii')
t3 = Table.read("""a b
M45 2012-02-03""", format='ascii')
In [19]:
x = hstack([t1, t2, t3])
print(x)
In [21]:
import numpy.ma as ma
In [22]:
x = np.array([1, 2, 3, -1, 5])
In [23]:
mx = ma.masked_array(x, mask=[0, 0, 0, 1, 0])
mx
Out[23]:
In [24]:
mx.data
Out[24]:
In [25]:
np.mean(mx.data)
Out[25]:
In [26]:
np.mean(mx)
Out[26]:
In [27]:
print(mx)
print(x)
In [ ]: