Dear,
The Gather method gathers values along an axis specified by dim. I would like to take the output, so the part that is discarded then the values by chosen indexes. How should I do this?
Thanks
Dear,
The Gather method gathers values along an axis specified by dim. I would like to take the output, so the part that is discarded then the values by chosen indexes. How should I do this?
Thanks
I am not 100% sure I understand what you attempt to do, but would scatter
ing a bool tensor True
to the indices and then taking the complement (using the ~
unary operator) and applying this as a mask in advanced indexing work?
inp = torch.arange(25.).view(5, 5)
idx = torch.randint(4, (5, 1)) + torch.tensor([0, 1])
res = inp[~torch.zeros(inp.shape,dtype=torch.bool).scatter_(1, idx, torch.tensor(True).expand(idx.shape))].view(inp.size(0), inp.size(1) - idx.size(1))
print(f"{inp=}\n{idx=}\n{res=}")
Best regards
Thomas
Thank you very much, this is the solution I needed.