附加错误Python

时间:2015-03-26 21:33:31

标签: python arrays numpy

#Each element of the FeatureFolds and ClassesFolds is a matrex by itself
#the classes are 5000x1 each
#the features are 5000 by 800 each


def FindAllVectors(c):


testC= c
FeatureFolds = [f1, f2 ,f3 ,f4 ,f5 ,f6 ,f7 ,f8 ,f9 ,f10]
ClassesFolds = [f1c ,f2c ,f3c ,f4c ,f5c ,f6c ,f7c ,f8c ,f9c ,f10c]
arr = np.array([])
for x in range(0,10):
    for y in range(0,5000):
        if (ClassesFolds[x][y][0]== testC):
            if (arr == []):
                arr = np.array(FeatureFolds[x][y]) 
            else:

                arr = np.append((arr, np.array(FeatureFolds[x][y])))

d= arr.shape
return d

返回错误: TypeError:append()至少需要2个参数(给定1个) 谁能解释为什么?

并且追加不会将其添加为新行?我该如何解决?

1 个答案:

答案 0 :(得分:2)

你的append行正在传递一个元组的一个参数而不是两个数组:

arr = np.append((arr, np.array(FeatureFolds[x][y])))
               #^- extraneous (  another one here -^

应该是

arr = np.append(arr, np.array(FeatureFolds[x][y]))