诸神缄默不语-个人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了,就可以正常运行了。

参考资料:

  1. ValueError: empty range for randrange() (1,1, 0)_醉小义的博客-CSDN博客
  2. random.randint()的官方文档

ValueError: empty range for randrange() (0, 0, 0)相关推荐

  1. 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 & ...

  2. 成功解决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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 成功解决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 ...

  8. 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 ...

  9. kafka中文文档(0.10.0)

    kafka中文文档(0.10.0) 作者:链上研发-老杨叔叔 时间:2016-07-22 版本:Apache Kafka 0.10.0 (2016年5月底发布) .目录 kafka中文文档0100 目 ...

最新文章

  1. Newtonsoft.Json文件错误
  2. 五大颠覆性特征带你认识6G网络
  3. 十、调度算法----时间片轮转、优先级调度、多级反馈队列
  4. Python | raise...from... 是个什么操作?
  5. mybatis 3.2.2_环境搭建
  6. Linux C文件编译
  7. Git笔记(11) 分支简介
  8. hadoop介绍及伪分布式搭建
  9. 实验六 Linux下文件程序设计
  10. 类的说明补充,对象的学习
  11. (三)树莓派系列教程:树莓派4B上编写Python程序(C语言),并运行
  12. 微信公众号做淘宝优惠券找券查券搜券和返利机器人的详细配置教程
  13. 计算机派位志愿填报技巧,小升初电脑大派位:大派位操作流程及志愿填报
  14. XDP/BPF Github教程
  15. python的回调函数和构造重载
  16. sigmoid函数是如何诞生的(最大熵原理)
  17. 微信小程序文本组件text使用详解-微信小程序系统学习攻略​
  18. Material Design - Curved motion
  19. 数字集成电路设计的流程1
  20. 华为机考攻略(python)--入门题【5题】(第一题HJ5进制转换)

热门文章

  1. windows安装Weblogic教程(图文教程超详细版)
  2. IPv6和IPv4共存技术之 ISATAP隧道技术
  3. 基于爬虫爬取的数据,完成数据展示网站
  4. JS document方法
  5. MySQL 自定义stuff函数
  6. 第五届蓝帽杯初赛:冬奥会_is_coming
  7. 机器人控制器编程整理汇总-辞旧迎新-
  8. 高温大量程热流传感器结构及信号调理电路的设计
  9. 晶体和晶振(晶体晶振区别、频率误差、负载电容)
  10. [Share] How To Ask Questions The Smart Way