# Selecting indices from list of indices

I have a 3D tensor of size (8,8,2052), all zeros. This will be the mask.
Also, there is a tensor of size (29, 3), which is basically a list of indices that need to be 1 in the mask.

Is there a pytorch way of doing this? im avoiding using python `for` loop, to iterate over the indices’ list.
so far i tried the following: take, index_select, “smart” indexing…

i put a lot of time on this, tried a lot of approaches and nothing seems to give me what im looking for.
Any ideas?

Here is an example of the indices list:

``````tensor([[0, 1, 0],

[0, 2, 0],

[0, 7, 0],

[1, 2, 0],

[1, 3, 0],

[1, 4, 0],

[1, 6, 0],

[1, 7, 0],

[2, 2, 0],

[3, 3, 0],

[3, 4, 0],

[4, 0, 0],

[4, 2, 0],

[4, 4, 0],

[4, 6, 0],

[5, 0, 0],

[5, 4, 0],

[5, 5, 0],

[5, 6, 0],

[6, 0, 0],

[6, 2, 0],

[6, 4, 0],

[6, 5, 0],

[6, 6, 4],

[7, 0, 0],

[7, 2, 1],

[7, 4, 2],

[7, 5, 40],

[7, 6, 0]])
``````

Could you post the “slow” loop approach so that we could check for a better way, please?

``````mask = torch.zeros((8,8,2052)) # in this case the depth is 2052, but can be much larger
idxs = tensor of size (29, 3) # the 29 can also be larger - (max is 8 * 8 * depth_of_mask)
for idx in idxs:
# idx is a tensor of size (1, 3),
# using unbind to get each number on its own
# and fing the right 'cell' in the mast