还是得按照这样取数据准,np.array是不准确的
import numpy as np
import torch
#下面这个是错误的:
x = torch.ones(2,2,requires_grad=False)
y= torch.ones(2,2,requires_grad=False)#.type(torch.uint8)
y[0,1]=0
x[np.array(y)]=0
print(x)
#这个是正确的:
x = torch.ones(2,2,requires_grad=False)
y= torch.ones(2,2,requires_grad=False).type(torch.uint8)
y[0,1]=0
x[y]=0
print(x)
这个也是准确的:
import torch #下面这个是错误的: x = torch.ones(2,2,requires_grad=False) y= torch.ones(2,2)#.numpy()#.astype(np.uint8)#.type(torch.uint8) # y[:]=np.asarray(y[:]) y=np.asarray([[1,1],[1,1]]) y[0,1]=0 x[torch.from_numpy(y).type(torch.uint8)]=0 print(x)
import torch
import numpy as np
#80 10 5 3:4
#80 3 11 11
a=torch.linspace(0,9,steps=10).view(1,2,5)
#随机int数
torch.randperm(5)