import pyfits as pf import numpy as np import matplotlib.pyplot as plt hdulist = pf.open("LE_evt.fits",mode='update') tb = hdulist[1].data x = tb.field(0) y = tb.field(1) print (x[-1]) t = tb[np.where(tb.field(5)==1)] #t6 = tb.field(6)[np.where(tb.field(5)==1)] hdulist[1].data = t hdulist.flush() hdulist.close()
注意np.where的用法返回的实际是指数(虽然help文档里写的是返回元素)