Absolute value of a n x 2 tensor row-wise

What is the most convenient way to calculate the row-wise abs value of two numbers across the first dimension of the tensor, i.e. the result should be a n-1 vector with the entries equal to sqrt(a^2 + b^2) for every row. Thanks in adance

SOmething like this?

import torch
a = torch.rand(10,2)
a
Out[4]: 
tensor([[0.9320, 0.5596],
        [0.9421, 0.9769],
        [0.2222, 0.6544],
        [0.6278, 0.9877],
        [0.3971, 0.8167],
        [0.3373, 0.7039],
        [0.4469, 0.9218],
        [0.8113, 0.8739],
        [0.6855, 0.1918],
        [0.5449, 0.7199]])
b=a.pow(2).sum(1).sqrt()
b
Out[6]: 
tensor([1.0871, 1.3572, 0.6911, 1.1704, 0.9081, 0.7805, 1.0244, 1.1925, 0.7118,
        0.9029])
a.norm(2,dim=1)
Out[7]: 
tensor([1.0871, 1.3572, 0.6911, 1.1704, 0.9081, 0.7805, 1.0244, 1.1925, 0.7118,
        0.9029])
1 Like