选择astropy选项卡的子集

2024-09-24 12:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个astropy表的子集。你知道吗

我被告知我需要使用numpy,但当我通过numpy访问表时,我似乎没有得到2d numpy表,并且感到困惑。你知道吗

我试图创建的表子集来自GAMA调查

我试过了

import numpy as np
from astropy.table import Table
t = Table.read('GAMA_Data/InputCatA.fits')
ta = np.array(t)

我希望执行一些子集,如

t['PETROMAG_I'] > 17.5)

我收到一些建议,我需要使用numpy。 我可以确定“PETROMG_I”是第16列

print(t.colnames.index('PETROMAG_I'))

但是不知道如何在表或numpy数组上创建子集

 print('Source Table : '+str(len(ta)))
 print('Shape : '+str(ta.shape))
 print(ta)

给予

Source Table : 960510
Shape : (960510,)
[(     0, 588848900971299297, 145.46972201, 0.65141891,           68987912448,        0, 3.0191224, 20.57372 , 20.748629, 4503874773745664, 0.3678997 , 2.9388053, 1.2919843 , 28.094984, 21.347776, 19.99194 , 19.40016 , 18.74607 , 22.722446, 21.583874, 19.939884, 19.270464, 18.782948,  9843, 756)
 (     1, 588848900971299302, 145.47892146, 0.63515137,       68987912448,        0, 3.3755734, 21.073107, 21.055092, 4503874773745664, 0.37012857, 3.619758 , 1.5749472 , 21.076248, 20.432001, 20.08754 , 19.929377, 20.802927, 21.622843, 20.553198, 20.045462, 19.874853, 19.653866,  9843, 756)

Tags: fromimportnumpysourceasnptable子集
1条回答
网友
1楼 · 发布于 2024-09-24 12:25:13

用途:

mask = t['PETROMAG_I'] > 17.5  # Makes a boolean selection mask (numpy array)
t_new = t[mask]  # Makes a new astropy Table

这将为您提供一个包含选定行的astropy表。这在本节底部附近的一个示例中有记录:https://docs.astropy.org/en/stable/table/access_table.html#accessing-data。你知道吗

相关问题 更多 >