index 0 does not match the shape of the indexed tensor [8, 8, 4] at index 0

这篇博客介绍了在遇到`index 0 does not match the shape of the indexed tensor [8, 8, 4] at index 0`这种错误时,如何进行问题定位和解决。关键点在于,解决方案涉及到将b的索引从nparray转换为tensor。" 12916343,1932395,AIX系统fsck修复:从故障到解析,"['AIX操作系统', '文件系统构架', '故障排查', 'fsck命令']
摘要由CSDN通过智能技术生成

 

index 0 does not match the shape of the indexed tensor [8, 8, 4] at index 0

解决后的;

b的索引是nparray,不是tensor,

b[np.asarray(a)]

 

import torch
import numpy as np

# 80 10 5 3:4
# 80 3 11 11
import copy
a = torch.linspace(-4, -1, steps=4)



a = torch.linspace(0, 7, steps=8).repeat(4,1).view(2,16).type(torch.uint8)
b = torch.linspace(1, 256, steps=256).view(8,8, 4)


#取单个值,
# a=[[0,0,0,1],[0,0,0,2]]#维度变了

b[np.asarray(a)]=0

print(b)
# if b[np.asarray(a)]==b[np.asarray(c)]:
#     print("11111111111")
# print(np.array(a))
#
# b[np.array(a)]=0

解决之前的:

import
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值