Python报错:IndexError: index 0 is out of bounds for axis 0 with size 0

简介: Python报错:IndexError: index 0 is out of bounds for axis 0 with size 0

Python报错:

IndexError: index 0 is out of bounds for axis 0 with size 0


原因:

索引超出了列表的长度

import numpy as np
a = np.empty(1)
print(a[1])
# IndexError: index 1 is out of bounds for axis 0 with size 1

或者

import numpy as np
a = np.empty(3)
print(a[5])
# IndexError: index 5 is out of bounds for axis 0 with size 3

解决方法:

检查是自己的索引错了, 还是数组长度定义错了

目录
相关文章
|
2月前
|
Linux Python
【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend'
ERROR: Error: No module named '_cffi_backend', Cannot find module. Please check the requirements.txt file for the missing module.
|
3月前
|
机器学习/深度学习 Shell 开发工具
Python使用管道执行git命令报错|4-7
Python使用管道执行git命令报错|4-7
|
3月前
|
Python
python常见报错
python常见报错
|
2月前
|
Python
Python的报错让我学到新知识
Python的报错让我学到新知识
19 0
|
2月前
|
数据采集 网络安全 Python
Python使用urllib或者urllib2模块打开网页遇到ssl报错
Python使用urllib或者urllib2模块打开网页遇到ssl报错
35 0
|
3月前
|
缓存 Python
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-npf9报错
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-npf9报错
|
3月前
|
JSON 安全 数据格式
7-6|python报错TypeError: can't pickle _thread.RLock objects
7-6|python报错TypeError: can't pickle _thread.RLock objects
|
7月前
|
Ubuntu Python
【Python】报错ModuleNotFoundError: No module named ‘XXX‘
【Python】报错ModuleNotFoundError: No module named ‘XXX‘
|
5月前
|
Python
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
383 0
|
5月前
|
机器学习/深度学习 文字识别 开发者
【Python】已解决:(paddleocr导包报错)ModuleNotFoundError: No module named ‘paddle’
【Python】已解决:(paddleocr导包报错)ModuleNotFoundError: No module named ‘paddle’
548 0