Issue
So here is what I can get with torch.eye(3,4)
now
The matrix I get:
[[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0]]
Is there any (easy)way to transform it, or make such a mask in this format:
The matrix I want:
[[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]
Solution
You can do it by using torch.diagonal
and specifying the diagonal you want:
>>> torch.diag(torch.tensor([1,1,1]), diagonal=1)[:-1]
tensor([[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]])
- If :attr:
diagonal
= 0, it is the main diagonal.- If :attr:
diagonal
> 0, it is above the main diagonal.- If :attr:
diagonal
< 0, it is below the main diagonal.
Answered By - Andreas K.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.