too many indices for tensor of dimension 3

这篇博客探讨了一个在处理Tensor时遇到的问题——'too many indices for tensor of dimension'。作者指出,当尝试访问的索引超过张量的维度时,会引发此错误。在特定情况下,将维度调整为一致或使用其他博客中的方法可以避免这个错误。举例来说,涉及tconf(80*3)、best_n(80*3)和gy(80)的张量操作导致了'too many indices for tensor of dimension 1'的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

too many indices for tensor of dimension 3

 

原因还未找到,只是感觉把维度换成一模一样就不报错了,或者换成另一片博文中的也可以。

 

too many indices for tensor of dimension

tconf是80*3

best_n也是80*3

gy是80

最后报错:too many indices for tensor of dimension 1

tconf[best_n][np.array(gy), np.asarray(gx)] = 1

 

 

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, 1, steps=2).repeat(16,1).view(16,2)
b = torch.linspace(1, 256, steps=256).view(8,8, 4)

print(np.array(a))
print(b<5)

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

b[np.asarray(a)]=0

print(b)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

AI算法网奇

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

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

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

打赏作者

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

抵扣说明:

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

余额充值