I have two tensors, A and B. A is of dimension [n+1, m]. B is of dimension [n,k] and all value are from -1 to m-1. What I need to to is check if the value in if any value in B is equal to -1. If it is, I will set it to value A[n+1]. If it is not, I will set the value to A[i]. For example, let A = [x_0, x_1, x_2, x_3,x_4] and B = [[0,-1,-1],[1,2,-1],[2,0,1]]. Then, I want to end up with C = [[x_0,x_4,x_4],[x_1,x_1,x_4],[x_3,x_3,x_3]]. I want this to be as efficient as possible, so I’m trying to avoid loops and stick to torch functions.
Any suggestion?