'Pytorch parallel functional calls for multiple locations in a tensor
Does anyone know if there is a function in PyTorch that allows you to call a particular function for all the locations in a tensor where a condition is satisfied? For example, for all the locations in a tensor where the value is equal to 100, a function has to be called without using any for loops. I want to modify other tensors for these locations. I know I can just get the list of locations and then call the function for each location but I want to avoid that. Thank you for your help. Something like torch.where(a==100,function1())
Adding more details after the request in the comments:
function1(x,y): #(x,y) are co-ordinates
... some code based on (x,y)...
a[x,y] = 20
b[x,y] = 10
Let's assume we have 2 2D(single row) tensors a = [1 2 100 100 5 6 200 8 2] and b=[3 4 5 5 6 10 3 8 9]. Now I want to pass the coordinates of where a == 100 in our case (0,2) and (0,3) to function1 and modify the values of a and b at those locations. I hope this helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|