ValueError: empty range for randrange() (0, 0, 0)
诸神缄默不语-个人CSDN博文目录
运行环境,报错信息、原因和解决方案:
Linux系统,Python3,random包。(在运行过程中使用了其他框架,与本错误无直接关系)
报错信息:
Traceback (most recent call last):File "my_path/myscript.py", line 302, in <module>i=random.randint(0,len(val_data)-1)File "mypath/lib/python3.8/random.py", line 248, in randintreturn self.randrange(a, b+1)File "mypath/lib/python3.8/random.py", line 226, in randrangeraise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0, 0, 0)
问题所在:我发现是因为获取数据(val_data
)的过程中出现了问题,导致val_data
为空列表,len(val_data)-1
为-1,小于0,而random.randint()
方法的第二个参数必须大于或等于第1个参数。
解决方式:使randint()
的第二个入参大于等于第一个入参,本例中即要求len(val_data)-1
>0
。
我修改获取数据的代码后,val_data
有了元素,len(val_data)-1
大于等于0了,就可以正常运行了。
参考资料:
- ValueError: empty range for randrange() (1,1, 0)_醉小义的博客-CSDN博客
- random.randint()的官方文档
ValueError: empty range for randrange() (0, 0, 0)相关推荐
- transforms.RandomCrop((img_h, img_w)) raise ValueError(empty range for randrange)(%d,%d, %d)
问题 File "E:/wj-lab/expStad/train.py", line 446, in <module>losses=train(epoch)File & ...
- 成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be ...
- ValueError: With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be emp
今天写代码labelmetovoc,即将labelme标注的转化为voc标准格式参考的这篇文章时遇到了如下问题: ValueError: With n_samples=0, test_size=0.2 ...
- ValueError With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be empt
ValueError: With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be emp ...
- ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em ...
- ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be emp
ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be emp ...
- 成功解决ValueError: min_samples_split must be an integer greater than 1 or a float in (0.0, 1.0]; got th
成功解决ValueError: min_samples_split must be an integer greater than 1 or a float in (0.0, 1.0]; got th ...
- java 怎么判断1_1.0_1.00是同一个数_php如何优雅的判断 0.0/0.00/0.000 是否为空? 测试过用empty函数不行...
php如何优雅的判断 0.0/0.00/0.000 是否为空? 测试过用empty函数不行 如何优雅 ? if ( (int) $number == 0) echo 'empty'; if ( flo ...
- kafka中文文档(0.10.0)
kafka中文文档(0.10.0) 作者:链上研发-老杨叔叔 时间:2016-07-22 版本:Apache Kafka 0.10.0 (2016年5月底发布) .目录 kafka中文文档0100 目 ...
最新文章
- Newtonsoft.Json文件错误
- 五大颠覆性特征带你认识6G网络
- 十、调度算法----时间片轮转、优先级调度、多级反馈队列
- Python | raise...from... 是个什么操作?
- mybatis 3.2.2_环境搭建
- Linux C文件编译
- Git笔记(11) 分支简介
- hadoop介绍及伪分布式搭建
- 实验六 Linux下文件程序设计
- 类的说明补充,对象的学习
- (三)树莓派系列教程:树莓派4B上编写Python程序(C语言),并运行
- 微信公众号做淘宝优惠券找券查券搜券和返利机器人的详细配置教程
- 计算机派位志愿填报技巧,小升初电脑大派位:大派位操作流程及志愿填报
- XDP/BPF Github教程
- python的回调函数和构造重载
- sigmoid函数是如何诞生的(最大熵原理)
- 微信小程序文本组件text使用详解-微信小程序系统学习攻略​
- Material Design - Curved motion
- 数字集成电路设计的流程1
- 华为机考攻略(python)--入门题【5题】(第一题HJ5进制转换)