Replace diagonal of matrix with new diagonal values

Numpy Version of the Code:


For Pytorch version, It seems like we cannot replace diagonal elements with a vector of elements and only a scalar value can be filled on diagonal.

This older post provides some approaches using direct indexing to fill the diagonal with a tensor.

1 Like

Thank you. It worked. I should have checked it better.