I am looking for an elegant way to select a subset of the torch tensor that satisfies some restrictions. For example, let's say I have:
A = torch.rand(10,2)-1
and S- tensor 10x1,
sel = torch.ge(S,5) -- this is a ByteTensor
I would like to be able to do logical indexing as follows:
A1 = A[sel]
But that does not work. So, a function indexthat accepts LongTensor, but I could not find an easy way to convert Sto LongTensor, except for the following:
sel = torch.nonzero(sel)
which returns the tensor K x 2 (K is the number of values S> = 5). So, I have to convert it to a 1-dimensional array, which finally allows me to index A:
A:index(1,torch.squeeze(sel:select(2,1)))
This is very cumbersome; in particular. Matlab, all i need to do is
A(S>=5,:)
Can anyone suggest a better way?