草庐IT

LongTensor

全部标签

python - 我可以使用逻辑索引或索引列表对张量进行切片吗?

我正在尝试使用列上的逻辑索引对PyTorch张量进行切片。我想要与索引向量中的1值对应的列。切片和逻辑索引都是可能的,但它们可以一起使用吗?如果是这样,如何?我的尝试不断抛出无用的错误TypeError:indexingatensorwithanobjectoftypeByteTensor.Theonlysupportedtypesareintegers,slices,numpyscalarsandtorch.LongTensorortorch.ByteTensorastheonlyargument.MCVE期望的输出importtorchC=torch.LongTensor([[1,