Hi Talip!



 talipturkmen:

As an example of the values
n = 4 (4x4 matrix)
a = 1
I want to get a matrix as follows.
[
[1,1,0,0],
[1,1,1,0],
[0,1,1,1],
[0,0,1,1]
]


I think that torch.tril() and/or torch.triu() will be the key to what you want.
Here is one specific approach:
>>> torch.__version__
'1.6.0'
>>> n = 4
>>> a = 1
>>> torch.tril (torch.ones ((n, n)), a) * torch.triu (torch.ones ((n, n)), -a)
tensor([[1., 1., 0., 0.],
        [1., 1., 1., 0.],
        [0., 1., 1., 1.],
        [0., 0., 1., 1.]])

Best.
K. Frank