numpy.concatenate合并矩阵报错ValueError: all the input arrays must have same number of dimensions

部分代码如下,试图把提取好的特征和标签进行合并

dataset1 = loadtxt('./1000.csv', delimiter=",")    # 10000*1000
X1 = dataset1[:,0:999]
dataset2 = loadtxt('./2000.csv', delimiter=",")    # 10000*2000
X2 = dataset2[:,0:1999]
target = dataset2[:,1999]

X1的shape为(10000,999), X2的shape为(10000,1999), target的shape为(10000,),由于dataset3[:,1999]只有一列, 在使用numpy.concatenate和X1,X2拼接时,作为一行而存在,因此报错.

 

解决方案:

使用np.column_stack()代替,对一维可处理

详细解释自行前往:

https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.column_stack.html

 

 

你可能感兴趣的:(numpy.concatenate合并矩阵报错ValueError: all the input arrays must have same number of dimensions)