AssertionError:块尺寸数(1)必须等于轴数(2)

时间:2015-11-01 06:27:04

标签: pandas

我正在研究分类问题并使用pandas库进行数据分析。使用pd.Dataframe()函数时,我收到上述错误。我是新手,并不理解这个错误的含义。以下是我的代码

`from scipy.misc import imread
import numpy as np
import os
import numpy as np
from sklearn.decomposition import RandomizedPCA
import pandas as pd
import pylab as pl
img_dir = 'pics/'
pics = [img_dir+ f for f in os.listdir(img_dir)]
def extrct_labels(filename):

    n = len(filename)
    y = np.zeros(n,dtype = np.int32)

    for i,filename in enumerate(filename): 
        # If 'check' string is in file name assign '0'
        if 'check' in str(filename):
            y[i] = 0
        else:
            y[i] = 1
    return y
data = []
for pic in pics:
    img = imread(pic)
    img = img.flatten()
    data.append(img)

data = np.array(data)
pca = RandomizedPCA(n_components=2)
X = pca.fit_transform(data)
df = pd.DataFrame({"x-1": X[:,0], "x-2": X[:,1], "label": np.where(y==1, "Driver's License", "Check")})
`

感谢任何帮助。

0 个答案:

没有答案