I think this summarizes it well. If B[i][j]!=-1, then C[i][j]=A[i]. else C[i][j]=A[-1]. I tried using where, but An issue I’m running into is A[i][j].size() != B[i][j].size(). I should specify, x_i is a tensor of length > 1