错误部分

错误原因

disp_image部分是一个维度为[1,4]的tensors。因此不可将元素逐个读取出来。

解决方案

将tensor转换成numpy, 再将numpy转换为list

具体做法

ndarray = disp_rect.cpu().numpy() #将tensor转换为ndarray
list = ndarray.tolist() #将ndarray转换为list

此时,已经把数据处理成可用状态,但是数据集中的tensor维度不一致,

导致仍然报错,具体来说为tensor有些维度为【1,4】,有些为【4,】也就是总维度为2/1维。因此

解决方案

将2维的部分降为1维

            if ndarray.shape[0] == 1:list = ndarray.tolist()re_rect = [token for set in list for token in set]

如果第一维为1,则进行降维操作,否则

         else:list = ndarray.tolist()

直接转换为list

经过此步骤可以使得tensor都成为【4,】

问题解决

ValueError:only one element tensors can be converted to Python scalars 解决方法相关推荐

  1. Pytorch BUG: ValueError:only one element tensors can be converted to Python scalars

    Pytorch BUG: ValueError:only one element tensors can be converted to Python scalars 这是由于把包含tensor的列表 ...

  2. only one element tensors can be converted to Python scalars

    only one element tensors can be converted to Python scalars for neg_step in range(neg_,float(con_pos ...

  3. torch把存放tensor的整个list都转为tensor ValueError}only one element tensors can be converted to Python scal

    别用torch.tensor直接转,用下边的 torch.stack(pos_temp)

  4. TypeError: only size-1 arrays can be converted to Python scalars

    正在愉快写代码的我 ??????????? 源代码也很简单 之后可以解决,比如 再比如: 但是那样究竟为什么不对呢? plt.bar(x = x,height=data,width=0.8,align ...

  5. 自学Python问题记录3:only size-1 arrays can be converted to Python scalars

    报错情况 only size-1 arrays can be converted to Python scalars/仅一维数据可以转换为Python标量 原因及解决方法 ax.bar(theta, ...

  6. 关于python出现ValueError: A value in x_new is below the interpolation range.的解决方法

    ValueError: A value in x_new is below the interpolation range. 在使用scipy.interpolate.interp1d()函数计算EE ...

  7. Python 空字符串转化问题:ValueError: invalid literal for int() with base 10: ' ',原因及解决方法。

    ValueError: invalid literal for int() with base 10: ' ' 翻译: 值异常:以10为基数的int()的无效文字:' ' int('')就会报错. 就 ...

  8. TypeError系列之:TypeError: only size-1 arrays can be converted to Python scalars

    这样一个错误是一个类型错误,翻译过来就是, 只有维度是1的数组可以被转换成Python标量. 出现这种问题的原因会很多,非常具体,但根本原因是维度错误!! 所以各位看官要查询出错位置,看看赋值的数据( ...

  9. ValueError: Unterminated string starting at: 一种可能的情形以及解决方法

    问题描述 使用 json.load() 时抛出异常. 代码重现 xxx json.dump(data, open('file_path', 'w'))xxxjson.load(open('file_p ...

最新文章

  1. 设计模式之原型模式prototype
  2. 如何保护自己的android app
  3. Java后端简历模板,转疯了!
  4. POJ 1321 棋盘问题(DFS 状压DP)
  5. python 生成html文件浏览器_Handout库:能将python脚本转化为html展示文件
  6. 【前端】【cornerstone】cornerstone.js如何编辑图像/加载已有图像数据(以画直线为例)
  7. 第三部分 SOA项目的运维
  8. 易智瑞大赛——地图故事组参赛经验
  9. matlab 读取.pgm,【数字图像处理】pbm/pgm/ppm图片的读写(Matlab)
  10. 为什么阿里巴巴规定禁止超过三张表 join
  11. PHPstorm 函数时间注释的修改   正常的PHPstorm里面函数方法的注释是没有动态时间设置的,但是看了PHP file里面有时间日期的注释,而PHP Function Doc Commen
  12. 创业者尽职调查之一:用户增长核算[英文版]
  13. 密码学系列之七:数字签名
  14. 与ANN的第一次约会:ANN是什么?
  15. Web3是未来还是大忽悠?
  16. 我的Linux运维笔记
  17. 移动互联网白皮书:Android 占到主导地位
  18. Spring Boot中使用WebJars
  19. 双核心校园网规划与设计
  20. 汽车Tbox是什么?

热门文章

  1. latex假装插入参考文献(不用bibtex)
  2. 【niubi-job——一个开源的分布式任务调度框架】-----安装教程
  3. NVisual 如何实现“数据中心光纤配线”智能化管理?
  4. startActivityForResult被标记为弃用后,如何优雅的启动Activity?
  5. 今晚7:30|UCLA 胡子牛博士——图神经网络及其自监督学习
  6. Python 介绍pylab和绘图设置显示中文的方法
  7. 龙尚科技借力中国移动布局物联网“大连接”
  8. MySQL5.7创建唯一索引时报错提示Duplicate entry * for key *
  9. 如何实现最佳的跨平台游戏体验?Unity成亮解密实时渲染
  10. RRAM 蕴含逻辑运算IMP