categorical[np.arange(n), y] = 1 IndexError: index 2 is out of bounds for axis 1 with size 2

我的错误的代码是:train_labels = np_utils.to_categorical(train_labels,num_classes = 3)

错误的原因:

IndexError: index 2 is out of bounds for axis 1 with size 2

错误的具体指向:

categorical[np.arange(n), y] = 1 

 

这是因为train_labels不是numpy.array的形式,需要把train_labels转化为numpy数组的形式

 

posted @ 2019-01-12 09:53  RamboBai  阅读(13159)  评论(0编辑  收藏  举报