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数组的形式