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 ...
torch.tril_indices — PyTorch 1.10.1 documentation
pytorch.org › generated › torchtorch.tril_indices. Returns the indices of the lower triangular part of a row -by- col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates. Indices are ordered based on rows and then columns. The lower triangular part of the matrix is defined as the elements on ...
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 ...
Modify array with list of indices - PyTorch Forums
discuss.pytorch.org › t › modify-array-with-list-ofOct 22, 2018 · Suppose I have a list of indices and wish to modify an existing array with this list. Currently the only way I can do this is by using a for loop as follows. Just wondering if there is a faster/ efficient way. torch.manual_seed(0) a = torch.randn(5,3) idx = torch.Tensor([[1,2], [3,2]]).to(torch.long) for i,j in idx: a[i,j] = 1 I initially assumed that gather or index_select would go some way ...