python错误为IndexError: too many indices for array 

可以解决的方法有如下方案:

You are getting this error because you are making target array ‘y’ 2-D which is actually needed to be 1-D to pass in cross validation function. 
These two cases are different: 
1. y=numpy.zeros(shape=(len(list),1)) 
2. y=numpy.zeros(shape=(len(list)))
 

初始化数组是一维的,二维的就会出错,将array=zeros(numberOFLines)改成array = zeros((numberOFLines,3)就可以解决错误了

或者采取reshape,将其转化为1一维  ,使用b.resize() 和squeeze函数都可以达到效果

 

原始代码是 

train_data=train_data[new_indices,:,:,:]

修改为

train_data=train_data[new_indices,2] ,因为是三维矩阵,从0开始
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐