我正在制作代码来计算星数据的SNR,并且无法使我的函数与列表一起工作

时间:2016-05-11 19:18:15

标签: python

TypeError                                 
Traceback (most recent call last)
<ipython-input-86-57daa474841c> in <module>()
      1 SNRb=[]
      2 for i in range(len(fb)): #set up our function to find all values of SNR for the corresponding B values in flux, sky, and r
----> 3     SNRb=SNR1(fb[i],skyb[i],rb[i]) #time= 1/60 minutes because the image was from a 1 second capture
      4     SNRb.append(SNRb)
      5 print(SNRb)

<ipython-input-85-b4e9ec515c0d> in SNR1(f, sky, r)
     28     fs=F+S #adding the background to the flux/n for simplicity
     29     fst=[(10/x)/60 for x in fs] #the factors inside the square root, simplified into 1 term
---> 30     return(ft*math.sqrt(fst))

TypeError: a float is required

In [ ]:

1 个答案:

答案 0 :(得分:3)

您的问题似乎是您正在通过math.sqrt list一个无法使用的对象。

您可能要做的是获取该列表中每个元素的平方根。您可以使用numpy来完成此操作并简化代码,但假设您没有安装代码,则可以使用以下列表理解:

return [ft * math.sqrt(fst_i) for fst_i in fst]