L2-norm of a tuple

Hi all,

I have a tuple like this:

(tensor([[ 5.0027e-03,  1.3885e-03, -6.4720e-03,  ...,  2.1762e-03,
           2.0357e-03,  1.0070e-03],
         [ 9.5693e-04,  7.5463e-04, -7.4230e-04,  ..., -1.4247e-03,
          -1.5754e-03,  2.6448e-03],
         [ 7.9327e-03,  3.3485e-03, -9.9604e-04,  ..., -4.5044e-03,
           8.2048e-03,  4.0572e-03],
         [-2.9638e-03, -2.4065e-03,  2.5752e-03,  ..., -3.0519e-06,
          -4.8047e-03,  8.5964e-03],
         [-3.7381e-03, -2.3508e-03,  5.2545e-03,  ..., -9.0683e-03,
          -1.0091e-02,  5.3170e-03],
         [ 3.2105e-03, -3.0882e-03, -1.7957e-03,  ..., -1.8002e-03,
          -1.5211e-03,  4.3075e-03]]),)

Which was generated by torch.autograd.grad(). I was wondering how can I calculate the l2-norm of such a tuple?


It looks like your tuple has only the first element set.
You could try torch.norm(x[0], 2).

Thanks a lot! it worked.