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