【发布时间】:2017-05-03 01:29:02
【问题描述】:
所以我一直在编写代码来标准化矩阵的元素,我使用的函数如下:
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'
关于如何修复它的任何想法? 附言这是一个KNN分类代码
【问题讨论】:
-
也许尝试将您的
Data转换为numpy.array? -
什么是
Data?
标签: python python-2.7 numpy attributeerror