Hi Usman!



 Usman_Mahmood:

I want to average the upper and lower triangle for each matrix i in N.


Probably the most direct approach is to average the matrix with its
transpose.  Here is an illustration for the 3-dimensional-tensor use
case you mention:
>>> torch.__version__
'1.7.1'
>>> t = torch.tensor ([[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 20, 30], [40, 50, 60], [70, 80, 90]]])
>>> (t + t.transpose (1, 2)) / 2
tensor([[[ 1.,  3.,  5.],
         [ 3.,  5.,  7.],
         [ 5.,  7.,  9.]],

        [[10., 30., 50.],
         [30., 50., 70.],
         [50., 70., 90.]]])

Best.
K. Frank