2014-06-10 39 views
0

我的整個程序是正確的(我已經在各個階段檢查過)。在此模塊中突出顯示的行,然而,返回錯誤:scipy.optimize.newton給出TypeError:只能連接元組(不是「int」)到元組

TypeError: can only concatenate tuple (not "int") to tuple 

我不知道爲什麼會這樣。 funcPsat返回浮點值。我將不勝感激任何有用的建議!

import scipy.optimize.newton as newton 

def Psat(self, T): 
    pop= self.getPborder(T) 
    boolean=int(pop[0]) 
    P1=pop[1] 
    P2=pop[2] 
    if boolean: 
     Pmin = min([P1, P2]) 
     Pmax = max([P1, P2]) 
     if Pmin > 0.0: 
      Pguess = 0.5*(Pmin+Pmax) 
     else: 
      Pguess=0.5*Pmax 
     solution = newton(self.funcPsat, Pguess, args=(T)) #error in this line 
     return solution 
    else: 
     return None 
+0

你能提供完整的錯誤追蹤?什麼是'T'? – jonrsharpe

回答

3

我認爲問題是,每個文件

args :tuple, optional

Extra arguments to be used in the function call.

args參數應該是一個tuple

只是放圓括號不會這樣做;元組的語法是逗號。例如:

>>> T = 0 
>>> type((T)) 
<type 'int'> 
>>> type((T,)) 
<type 'tuple'> 

嘗試:

solution = newton(self.funcPsat, Pguess, args=(T,)) 
               #^note comma 
+0

謝謝喬恩!有用!好極了! –

相關問題