小编Fer*_*med的帖子

AttributeError:“元组”对象没有属性“ shape”

因此,我一直在编写代码以标准化矩阵的元素,而我使用的函数如下:

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
Run Code Online (Sandbox Code Playgroud)

它在类外运行很好,但是在类内使用时却出现此错误:

  AttributeError: 'tuple' object has no attribute 'shape'
Run Code Online (Sandbox Code Playgroud)

关于如何解决它的任何想法吗?PS这是KNN分类代码

python numpy attributeerror python-2.7

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

attributeerror ×1

numpy ×1

python ×1

python-2.7 ×1