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

解决方法:

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

sagima
+关注
目录
打赏
0
0
0
0
13
分享
相关文章
【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.
|
4月前
|
Python的报错让我学到新知识
Python的报错让我学到新知识
37 0
Python使用urllib或者urllib2模块打开网页遇到ssl报错
Python使用urllib或者urllib2模块打开网页遇到ssl报错
49 0
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报错
7-6|python报错TypeError: can't pickle _thread.RLock objects
7-6|python报错TypeError: can't pickle _thread.RLock objects
【Python】报错ModuleNotFoundError: No module named ‘XXX‘
【Python】报错ModuleNotFoundError: No module named ‘XXX‘
|
7月前
|
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
430 0
【Python】已解决:(paddleocr导包报错)ModuleNotFoundError: No module named ‘paddle’
【Python】已解决:(paddleocr导包报错)ModuleNotFoundError: No module named ‘paddle’
606 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等