2013-11-27 97 views
0

這裏的錯誤:在範圍對於j(LEN(rotlati)):類型錯誤:類型 '浮動' 對象沒有LEN()

類型錯誤:類型 '浮動' 的對象沒有LEN()

我見過很多其他帖子,但我還沒有找到解決方案。 我有點困惑。如果你知道這裏發生了什麼,請發表評論。

的代碼是:

m = 22 
rlati = numpy.zeros(m) 
n = 22 
rlongi = numpy.zeros(n) 

v = numpy.ndarray((2,),float) 

for j in range (len(lati)): 
LA = lati[j] 
    rlati[j] = LA - latiref 

    for i in range (len(longi)): 
     LO = longi[i] 

    rlongi[i] = LO - longiref 

    v[0] = rlati[j] 
    v[1] = rlongi[i] 

    vv = numpy.matrix(v) 
    #transpose of vv as vv.T 
    vv = vv.T 

    #proper rotation 
    vn = R*vv 

    #define how many decimals 
    vn = numpy.around(vn, decimals =2) 

    # rotation of the second column (lati) and third line (longi) 
     rotlati = float(vn[0]) 
    rotlongi = float(vn[1]) 

s = 22 
latidef = numpy.zeros(s) 
p = 22 
longidef = numpy.zeros(p) 

for j in range (len(rotlati)): 
RLA = rotlati[j] 

    latidef[j] = RLA + latiref 

for i in range (len(rotlongi)): 
     RLO = rotlongi[i] 

    longidef[i]= RLO + longiref 

    RLADEF = latidef[j] 
    RLODEF = longidef[i] 

    return RLADEF, RLODEF 
+3

嘛,'rotlati'是'float',不支持'LEN()'。你不明白什麼? –

回答

3

的錯誤是它到底是什麼說。 rotlatifloat。你不能把len()float。看看你的代碼,看起來好像你可能有意思是創建列表調用rotlatirotlongi並在你的range(len(lati))循環的每次迭代中追加到它們。相反,您現在只是在每次迭代時重寫相同的兩個浮點變量。

0

我得到了正確的答案,試試這個:

lloyd = { 
    "name": "Lloyd", 
    "homework": [90.0, 97.0, 75.0, 92.0], 
    "quizzes": [88.0, 40.0, 94.0], 
    "tests": [75.0, 90.0] 
} 

alice = { 

    "name": "Alice", 
    "homework": [100.0, 92.0, 98.0, 100.0], 
    "quizzes": [82.0, 83.0, 91.0], 
    "tests": [89.0, 97.0] 
} 
tyler = { 

    "name": "Tyler", 
    "homework": [0.0, 87.0, 75.0, 22.0], 
    "quizzes": [0.0, 75.0, 78.0], 
    "tests": [100.0, 100.0] 
} 

numbers = [] 

def average(numbers): 

    total = float(sum(numbers)) 
    return total/len(numbers) 
相關問題