Suppose I have a 1D PyTorch tensor end_index of length L.
I want to construct a 2D PyTorch tensor T with L lines where
T[i,j] = 2 when j < end_index[i] and T[i,j] = 1 otherwise.
The following works:
T = torch.ones([4,3], dtype=torch.long)
for element in end_index:
T[:, :element] = 2
Is there a vectorizd way to do this?