Reputation: 2072
I have a LongTensor which contains all the indices I want from another tensor. How can I convert this LongTensor into a ByteTensor that can be used as a selection mask.
Assume,
th> imageLabels:size()
17549
3
[torch.LongStorage of size 2]
[0.0001s]
th> indices
1
22
32
[torch.LongTensor of size 3]
I need a way to access imageLabels using [index]
notation so that I can change some values in imageLabels in-place.
Is there any way to do this? As far as I understood from the docs, :index, :narrow operations return a completely new Tensor.
Upvotes: 0
Views: 351
Reputation: 2072
I ended up using indexFill.
targetTensor:indexFill(1, indices, 0)
Hope this helps. Its all in the docs. We have to read it patiently.
Upvotes: 0
Reputation: 1
Correct, :index, narrow return a new tensor, the new tensor uses the same original storage as stated in the doc here: "For methods narrow, select and sub the returned tensor shares the same Storage as the original"
Upvotes: 0