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分類代碼
也許嘗試轉換你的'Data'成'numpy.array'? –
什麼是數據? – hpaulj