in

Merge one tensor into other tensor on specific indexes in PyTorch


Any efficient way to merge one tensor to another in Pytorch, but on specific indexes.

Here is my full problem.

1- I have a list of indexes of a tensor. I need to preserve them and apply some function on elements other than those indexes (For simplicity let say function is multiply them with two),

indexes=[1,2,55,44,66,99,3,65,47,88,99,0]

Then merge them back into the original tensor.

This is what I have done so far:
I create a mask tensor

indexes=[1,2,55,44,66,99,3,65,47,88,99,0]
xy = torch.rand(100,4)
mask=[]
for i in range(0,xy.shape[0]):
    if i in indexes: 
         mask.append(False)  
    else:
        mask.append(True)
print(mask)
import numpy as np
target_mask = torch.from_numpy(np.array(mask, dtype=bool))
print(target_mask.sum()) #output is 89 as these are element other than preserved. 

Apply the function on masked rows

zy = xy[target_mask]
print(zy)
zy=zy*2
print(zy)

Here is the sudo code I made, as one can see it is too complex and need 3 for loops to complete the task. and it will be too much resources waste.

#sudo code
for masked_row in indexes: 
    for xy_rows_index in xy: 
        if xy_rows_index= masked_row
            pass
        else:
            take zy tensor row and replace here #another loop to read zy. 

But I am not sure what is an efficient way to merge them, as I don’t want to use NumPy or for loop etc. It will make the process slow, as the original tensor is too big and I am going to use GPU.

Any efficient way in Pytorch for this?



Source: https://stackoverflow.com/questions/70715968/merge-one-tensor-into-other-tensor-on-specific-indexes-in-pytorch

Fake Firebase Performance for use during Flutter unit & widget tests

RRB Mumbai NTPC Result and Cut-Off Marks 2021 Out