LeeOrange_13 2022-10-26 22:44 采纳率: 100%
浏览 145
已结题

np_utils.to_categorical()IndexError: index -2147483648 is out of bounds for axis 1 with size 2

问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图

```python
Traceback (most recent call last):
  File "D:\Desktop\coding\res_machinelearning\pythonProject\Protrain.py", line 33, in <module>
    x_train, y_trian, x_test, y_test = prepare_data(w2id, sentences, labels, 200)
  File "D:\Desktop\coding\res_machinelearning\pythonProject\Prodataprocess.py", line 35, in prepare_data
    return np.array(X_train), np_utils.to_categorical(y_train,num_classes=2), np.array(X_val), np_utils.to_categorical(y_val,num_classes=2)
  File "D:\Desktop\coding\res_machinelearning\pythonProject\venv\lib\site-packages\keras\utils\np_utils.py", line 73, in to_categorical
    categorical[np.arange(n), y] = 1
IndexError: index -2147483648 is out of bounds for axis 1 with size 2

###### 运行结果及报错内容 
IndexError: index -2147483648 is out of bounds for axis 1 with size 2是为何呢?
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 11月3日
    • 创建了问题 10月26日

    悬赏问题

    • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
    • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
    • ¥15 数字信号处理考试111
    • ¥15 allegro17.2生成bom表是空白的
    • ¥15 请问一下怎么打通CAN通讯
    • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
    • ¥35 navicat将excel中的数据导入mysql出错
    • ¥15 rt-thread线程切换的问题
    • ¥15 高通uboot 打印ubi init err 22
    • ¥15 R语言中lasso回归报错