我有宇宙微波背景的健康地图。每张地图都有三个字段。我在代码中编写了以下函数来计算一般地图数量的第一个字段的功率谱:
def ps_TT(files):
c=[]
for i in range (0, len(files)):
#reads each map in turn
lmap=hp.read_map(files[i], field=(0,1,2))
#calculates the power spectra for all fields for each map
cl_lmap=hp.sphtfunc.anafast(lmap)
#selects the first field of the power spectra calculated for each map
cl_TT=cl_lmap[0]
#puts the results in the list c
c.append(cl_TT)
return c
'files' 输入是映射文件名的数组作为字符串。上面的代码为 ipython 中的 10 个映射返回以下输出:
In [4]: print ps_TT
[array([ 5.17445252e-04, 1.14526987e-03, 1.73325663e+03, ...,
2.38082865e-04, 2.50555631e-04, 2.53376503e-04]), array([ 1.45351786e-02, 6.01176345e-03, 1.27994240e+03, ...,
2.45848964e-04, 2.57155084e-04, 2.61421094e-04]), array([ 1.50848754e-03, 1.20842536e-02, 4.24761289e+02, ...,
2.56162191e-04, 2.47074545e-04, 2.58200020e-04]), array([ 7.59059129e-04, 1.40839130e-03, 1.00377030e+03, ...,
2.56563612e-04, 2.52381965e-04, 2.49896550e-04]), array([ 5.13876807e-04, 2.05938986e-02, 2.90047155e+02, ...,
2.53182443e-04, 2.50890172e-04, 2.50914303e-04]), array([ 1.54646117e-02, 6.75181707e-03, 1.90852416e+03, ...,
2.42936214e-04, 2.60074106e-04, 2.40752858e-04]), array([ 2.24837030e-02, 1.25850426e-03, 1.68506209e+03, ...,
2.51372591e-04, 2.45068513e-04, 2.50685742e-04]), array([ 2.16127178e-03, 6.70720310e-03, 1.55092736e+03, ...,
2.56133055e-04, 2.55980054e-04, 2.47690501e-04]), array([ 3.62577651e-05, 2.76265910e-03, 1.39297592e+03, ...,
2.64044826e-04, 2.67847727e-04, 2.56234516e-04]), array([ 7.69252941e-03, 4.32015790e-04, 1.34833309e+03, ...,
2.42188570e-04, 2.53480172e-04, 2.42193006e-04])]
这在一个列表中有 10 个数组。每个阵列具有特定地图的第一场功率谱数据。我想要做的是在我的代码中调用此列表中的各个数组,以便对每个单独的数据数组执行一个函数。
我看了个数组里面的pages Array?和访问python中数组列表中的元素,但没有发现任何一个像我希望的那样有用。