Unable to get repr for <class 'torch.Tensor'>
tensor越界访问后就会变成这样。
import torch
a_data=torch.Tensor([1,2,3])
index=[0,1,1,2,1]
ba=a_data[index]
print(ba)
labels[[0,5]]
2021.03.28测试发现越界错误好像又改了:
import torch
a_data =torch.Tensor([1 ,2 ,3])
index =[0 ,1 ,1 ,2 ,5]
ba =a_data[index]
print(ba)
报错内容:
IndexError: index 5 is out of bounds for dimension 0 with size 3
错误原因:a_data中只有3个数
但是index中有取第5个数(由于从0开始编号,实际是第6个数),越界报错。