I would like to select the rows which are not indexed by a indexing list, such as:
x = torch.randn(10)
indexing_list = torch.LongTensor([2,5])
x[-indexing_list] # What I want to do: remove out rows which are not indexed, thus there remains 8 items
anyone has a good idea?
BTW, is it faster to use LongTensor as an indexing list or maybe just same as np.array and primitive list?
Not knowing precisely the use case, I’d suggest something like: (i) transform your undesired indexes in a set, (ii) construct a list of the complement of your indexes.
python -m timeit --setup="import torch;x = torch.rand(10 ** 5);not_idx = set(torch.randint(10 ** 5, (10 ** 5,)).tolist())" "x[[e for e in range(10 ** 5) if e not in not_idx]]"