IndexError: tensors used as indices must be long, byte or bool tensors
下面的程序会报错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相关推荐
- 异常: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 ...
- 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(( ...
- 成功解决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 ...
- 【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 ...
- 【Sketch2Pose项目环境搭建】win10+Anoconda+VScode
最近我尝试在windows上运行Sketch2Pose这个项目,但前前后后花了很久,疯狂踩坑,嗯,很崩溃,遇到很多问题.于是写这篇博客,结合原仓库Readme内容,记录一下项目环境搭建的过程. 搭建环 ...
- 三元组损失tripletloss
雷郭出品 先验知识 1.Triplet loss 2. Hard Triplets选择 先验知识 题外话(来自网络): (最近,learning to rank 的思想逐渐被应用到很多领域,比如goo ...
- 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 ...
- 【TensorFlow_Fold】深度探究 Blocks for Input
0x00 前言 想写点东西试试,结果输入就死活搞不定,一万个TypeError: 决定学跑之前先学爬,老老实实啃一下源码和官方文档,虽然官方还在一点点更新,不少地方还是空白的,不过先动起来多敲点试试看 ...
- PyTorch 高级实战教程:基于 BI-LSTM CRF 实现命名实体识别和中文分词
20210607 https://blog.csdn.net/u011828281/article/details/81171066 前言:译者实测 PyTorch 代码非常简洁易懂,只需要将中文分词 ...
最新文章
- 本构二次开发 c语言,umat二次开发超弹性本构.doc
- 分布式图处理引擎Graph Engine 1.0 预览版正式发布
- Java程序员从笨鸟到菜鸟之(四)java开发常用类(包装,数字处理集合等)(上)
- 消息中间件:RocketMQ 介绍(特性、术语、原理、优缺点、消息顺序、消息重复)
- 查找(洛谷P2249题题解,C++语言描述)
- 参加 CSDN 2009 英雄大会有感(二)
- Android应用开发实例篇(1)-----简易涂鸦板
- CentOS7安装Java,java高级面试笔试题
- spring 5.x(1)-----Spring Framework 5.x中的新功能
- 苹果公布了一些最新无人车进展,但,研发依然缓慢
- mc java 连接超时_Java进程CPU占用高导致的网页请求超时的故障排查
- Django项目实践2 - Django模板(网页多语种支持/国际化)
- 六度空间的应用——找出两个陌生人之间的关系(二)
- GHOST常用参数详解,让你成为GHOST高手(转)
- Select at least one project的解决方法
- 车辆出险理赔记录接口文档
- 67.220.90.4 forum index.php,http://67.220.92.14/forum/inde PHP注释实例技巧
- 手把手教你用 Pygame 复刻游戏
- vs警告 当前源代码跟内置的版本不一致解决办法
- MIPS微程序CPU设计