Tensor indexing with another tensor - PyTorch Forums
https://discuss.pytorch.org/t/tensor-indexing-with-another-tensor/11448511.03.2021 · Hi, I usually index tensors with lists of indices, like x = torch.as_tensor([[1,2,3,4,5], [6,7,8,9,0]]) index = [[0, 1, 1], [1, 1, 2]] # tensor([2, 7, 8]) x[index] Now I need index to be a tensor object, but doing this, I get an error: x = torch.as_tensor([[1,2,3,4,5], [6,7,8,9,0]]) index = torch.as_tensor( [[0, 1, 1], [1, 1, 2]]) # IndexError: index 2 is out of bounds for dimension 0 with ...
Selecting element on dimension from list of indexes ...
https://discuss.pytorch.org/t/selecting-element-on-dimension-from-list...03.02.2019 · I’m implementing an LSTM on audio clips of different sizes. After going through padding/packing, the output of the lstm is: a.shape = torch.Size([16, 1580, 201]) with (batch, padded sequence, feature). I also have a list of the actual lengths of the sequences: lengths = [1580, 959, 896, 881, 881, 881, 881, 881, 881, 881, 881, 881, 881, 335, 254, 219]. What I would …
Index tensor with list - PyTorch Forums
discuss.pytorch.org › t › index-tensor-with-listNov 17, 2018 · I have a tensor T of shape (x, y) and a list L of shape (x), containing numbers [0, y). I want to have a tensor of shape (x), where each the ith element is T[i, L[i]]. I need this to be differentiable, and ideally with only pure torch operations and without loops. Apparently, T[:, L] gives a tensor of shape (x, x), where every element of L indexes every row. Currently, I’m using this ...
Index tensor with list - PyTorch Forums
https://discuss.pytorch.org/t/index-tensor-with-list/2984417.11.2018 · I have a tensor T of shape (x, y) and a list L of shape (x), containing numbers [0, y). I want to have a tensor of shape (x), where each the ith element is T[i, L[i]]. I need this to be differentiable, and ideally with only pure torch operations and without loops. Apparently, T[:, L] gives a tensor of shape (x, x), where every element of L indexes every row. Currently, I’m using …
torch.index_select — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.index_select(input, dim, index, *, out=None) → Tensor. Returns a new tensor which indexes the input tensor along dimension dim using the entries in index which is a LongTensor. The returned tensor has the same number of dimensions as the original tensor ( input ). The dim th dimension has the same size as the length of index; other dimensions have the same size as in the original tensor.