1。 list 转tensor
torch.FloatTensor([[1, 2, 3], [4, 5, 6]])
2 。index_fill_(dim,index,val)按照参数index总的索引数确定的顺序,将原tensor用参数val值填充
x = torch.Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
index = torch.LongTensor([0, 2])
x.index_fill_(1, index, 8)#([[8., 2., 8.],
# [8., 5., 8.],
# [8., 8., 8.]])
3.numpy 转tensor
filter=np.array([[1],[2]])
filter= torch.from_numpy(filter)