网上有很多不同类型的解决的方法,比如重置索引,排重索引等等。但对于我这段出错的代码却不适合。
def takeLabel(self, x_train, y_train ):
counter = x_train.shape[0] -1
s_n = x_train
s_p = x_train
while(1):
if( y_train[counter] == 1 ):
s_n = np.delete(s_n, counter, axis=0 )
else:
s_p = np.delete(s_p, counter, axis=0 )
这里x_train是Dataframe的形式,我打印了他的索引,并且都重置或者查重了索引,发现并没有问题。具体为什么爆这个错误,个人由于初学,也不是很理解ValueError: Shape of passed values is (179, 43), indices imply (180, 43)
这个错误具体原因。
于是我就猜测把他转为了x=np.array(x)
结果发现就可以进行np.delete了。