Issue
I have a tensor t of dim n x 3
. When I apply torch.linalg.norm
it returns one single value. What I need is a batch-wise norm function which will return a tensor with n norms, one for each vector in t.
Thanks for your help.
Solution
It seems the most relevant documentation place is: https://pytorch.org/docs/stable/generated/torch.linalg.norm.html
In the terminal you could try: python3
and then the following python commands:
>>> from torch import linalg as LA
>>> c = torch.tensor([[1., 2., 3.],
... [-1, 1, 4]])
>>> LA.norm(c, dim=0)
tensor([1.4142, 2.2361, 5.0000])
>>> LA.norm(c, dim=1)
tensor([3.7417, 4.2426])
Conclusion: In your specific case you will need to do:
torch.linalg.norm(t,dim=1)
Answered By - Kolyan1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.