2016-12-17 103 views
0

所以,我一直在寫代碼如下規範矩陣的元素,我使用的功能是:AttributeError的:「元組」對象有沒有屬性「形狀」

def preprocess(Data): 
    if stdn ==True: 
     st=np.empty((Data.shape[0],Data.shape[1])) 
     for i in xrange(0,Data.shape[0]): 
      st[i,0]=Data[i,0] 
     for i in xrange(1,Data.shape[1]): 
      st[:,i]=((Data[:,i]-np.min(Data[:,i]))/(np.ptp(Data[:,i])))  
      np.random.shuffle(st) 
     return st 
    else: 
     return Data 

它非常好之外該類但內部使用它時,它給了我這個錯誤:

AttributeError: 'tuple' object has no attribute 'shape' 

任何想法,我怎麼能解決它? P.S.這是一個KNN分類代碼

+0

也許嘗試轉換你的'Data'成'numpy.array'? –

+0

什麼是數據? – hpaulj

回答

1

根據您發佈的錯誤,Data是類型元組,並且沒有爲數據定義的屬性shape定義。你可以嘗試鑄造Data當你打電話給你preprocess功能,例如:

preprocess(numpy.array(Data)) 
相關問題