Hi All,
I have a quick question about merging 2 tensors together. Let’s say I have 1 tensor of shape [N,] which represents the diagonal of an N by N matrix. And another matrix which is of shape [N, N-1] and represents the off-diagonal elements, is it at all possible to merge the two different tensors together in an efficient way?
For example, the two tensors below (where I’ve given the values as the indices for ease of reading) would be merged into a single tensor (defined as matrix)
diag = torch.Tensor([11,22,33,44])
off_diag = torch.Tensor([[12,13,14],
                         [21,23,24],
                         [31,32,34],
                         [41,42,43]])
matrix = merge_diag_and_offdiag(diag, off_diag)
#returns torch.tensor([[11,12,13,14],
#                     [21,22,23,24],
#                     [31,32,33,34],
#                     [41,42,43,44]])

Is this at all possible? Any help is appreicated!