0

i'm trying to run this loop in my program to calculate the average of H I need to calculate value's of 2 arrays for each element of those arrays and then add them up.

 Htot = 0
 for i in range (0, len(redshift)):
 H = ((300000*redshift[i])/(np.power(10, (appmag[i]-19.0+5)/5))
 Htot = Htot + H

 Hgem = Htot/len(redshift)
 print Htot

But I get an invalid syntax error at Htot = Htot + H

4

2 回答 2

3

You forgot to close a parenthesis on the previous line.

There are too many anyway, these are enough:

H = 300000 * redshift[i]  / np.power(10, (appmag[i] - 19.0 + 5) / 5)
于 2013-04-01T12:23:43.733 回答
1

您的代码中的问题在第 3 行,您没有关闭行尾的括号复制此代码并执行它

Htot = 0
for i in range (0, len(redshift)):
    H = (( 300000 * redshift[i] ) / ( np.power(10, (appmag[i] - 19.0 + 5) / 5) ))
    Htot = Htot + H
Hgem = Htot/len(redshift)
print Htot
于 2013-04-01T13:45:17.673 回答