2015-02-05 305 views
0
first = int(list1[0] + list1[1]) 

a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23 = map(float, list1) 

if first == 11: 
      c = con.execute("SELECT Centroid FROM Centroid WHERE ItemID = 1") 
      centroid = c.fetchone() 
      AA = (min(a1, a2) * centroid) + (pow(a3,2)) 
      BB = (min(a1, a2) + a3) 
      WA = AA/BB 
      print (WA) 

以上是我的代碼。我現在的問題是,我得到一個錯誤:TypeError:不能用'float'類型的非整數來乘序列。 Python 3

TypeError: can't multiply sequence by non-int of type 'float'

我使用的變量(A1,A2,A3,質心)是一種浮動的。

+0

'map'是否在Python 3中返回一個生成器?這會導致'min(,None)* 1.4',這將解釋錯誤。而且,無論如何,列表理解似乎比'map'更受歡迎。嘗試用'[float(x)爲list1中的x'替換'map(...)'' – 2015-02-05 14:37:44

+0

您確定這些類型嗎?你檢查了嗎?尤其要檢查「質心」。當你從SQL查詢中得到它時,你爲什麼期望它成爲'float'? – 2015-02-05 14:54:23

回答

2

您需要將元組中心的第一個元素用作值type(centroid) is tupleTrue。使用:

centroid = c.fetchone()[0] 
相關問題