下面的程序会报错IndexError: tensors used as indices must be long, byte or bool tensors

mask = torch.Tensor([True,True,False])
a = torch.Tensor([3,2,1])
a[mask]=0
print(a)

原因是索引要为long, byte 或 bool类型,因此需要将mask转换为bool类型,如下:

mask = torch.Tensor([True,True,False]).type(torch.bool)
a = torch.Tensor([3,2,1])
a[mask]=0
print(a)
tensor([0., 0., 1.])

IndexError: tensors used as indices must be long, byte or bool tensors相关推荐

  1. 异常:IndexError: tensors used as indices must be long, byte or bool tensors

    异常:IndexError: tensors used as indices must be long, byte or bool tensors 详细异常 Traceback (most recen ...

  2. tensors used as indices must be long or byte tensors

    tensors used as indices must be long or byte tensors import torch import numpy as np a=torch.zeros(( ...

  3. 成功解决IndexError: arrays used as indices must be of integer (or boolean) type

    成功解决IndexError: arrays used as indices must be of integer (or boolean) type 目录 解决问题 解决思路 解决方法 解决问题 I ...

  4. 【pyradiomics】bugFix:GLCM特征时:IndexError: arrays used as indices must be of integer (or boolean) type

    GLCM特征时出现bug:IndexError: arrays used as indices must be of integer (or boolean) type 解决方法:https://gi ...

  5. 【Sketch2Pose项目环境搭建】win10+Anoconda+VScode

    最近我尝试在windows上运行Sketch2Pose这个项目,但前前后后花了很久,疯狂踩坑,嗯,很崩溃,遇到很多问题.于是写这篇博客,结合原仓库Readme内容,记录一下项目环境搭建的过程. 搭建环 ...

  6. 三元组损失tripletloss

    雷郭出品 先验知识 1.Triplet loss 2. Hard Triplets选择 先验知识 题外话(来自网络): (最近,learning to rank 的思想逐渐被应用到很多领域,比如goo ...

  7. All input tensors must be on the same device

    All input tensors must be on the same device RuntimeError: All input tensors must be on the same dev ...

  8. 【TensorFlow_Fold】深度探究 Blocks for Input

    0x00 前言 想写点东西试试,结果输入就死活搞不定,一万个TypeError: 决定学跑之前先学爬,老老实实啃一下源码和官方文档,虽然官方还在一点点更新,不少地方还是空白的,不过先动起来多敲点试试看 ...

  9. PyTorch 高级实战教程:基于 BI-LSTM CRF 实现命名实体识别和中文分词

    20210607 https://blog.csdn.net/u011828281/article/details/81171066 前言:译者实测 PyTorch 代码非常简洁易懂,只需要将中文分词 ...

最新文章

  1. 本构二次开发 c语言,umat二次开发超弹性本构.doc
  2. 分布式图处理引擎Graph Engine 1.0 预览版正式发布
  3. Java程序员从笨鸟到菜鸟之(四)java开发常用类(包装,数字处理集合等)(上)
  4. 消息中间件:RocketMQ 介绍(特性、术语、原理、优缺点、消息顺序、消息重复)
  5. 查找(洛谷P2249题题解,C++语言描述)
  6. 参加 CSDN 2009 英雄大会有感(二)
  7. Android应用开发实例篇(1)-----简易涂鸦板
  8. CentOS7安装Java,java高级面试笔试题
  9. spring 5.x(1)-----Spring Framework 5.x中的新功能
  10. 苹果公布了一些最新无人车进展,但,研发依然缓慢
  11. mc java 连接超时_Java进程CPU占用高导致的网页请求超时的故障排查
  12. Django项目实践2 - Django模板(网页多语种支持/国际化)
  13. 六度空间的应用——找出两个陌生人之间的关系(二)
  14. GHOST常用参数详解,让你成为GHOST高手(转)
  15. Select at least one project的解决方法
  16. 车辆出险理赔记录接口文档
  17. 67.220.90.4 forum index.php,http://67.220.92.14/forum/inde PHP注释实例技巧
  18. 手把手教你用 Pygame 复刻游戏
  19. vs警告 当前源代码跟内置的版本不一致解决办法
  20. MIPS微程序CPU设计

热门文章

  1. python中的类方法和静态方法
  2. LightGBM——提升机器算法(图解+理论+安装方法+python代码)
  3. 如何使用ListView实现一个带有网络请求,解析,分页,缓存的公共的List页面来大大的提高工作效率
  4. Tensorflow修改张量特定位置元素的值
  5. 如何做一名优秀的电子工程师[zz]
  6. JVM核心——JVM运行和类加载全过程
  7. 模仿u-boot的makefile结构
  8. 关于字节对齐以及内存占用
  9. K-Means ++ 算法
  10. UVA11427概率期望+独立重复事件