Any explain the usage of torch.norm when deal with 1d/2d/>2d tensor

hi, I found the API document from official website is hard for me to understand.

torch.norm(tensor, p...)
p (int, float, inf, -inf, 'fro', 'nuc', optional) –
the order of norm. Default: 'fro'

I know there is a difference between matrix norm and vector norm.
the the problem is , all data is denoted by tensor, therefore, how do the pytorch know when to apply matrix norm or vector norm for give tensor?

it depends on the dim argument.

As written in the document:

dim (int, 2-tuple of python:ints, 2-list of python:ints, optional) – If it is an int, vector norm will be calculated, if it is 2-tuple of ints, matrix norm will be calculated. If the value is None, matrix norm will be calculated when the input tensor only has two dimensions, vector norm will be calculated when the input tensor only has one dimension. If the input tensor has more than two dimensions, the vector norm will be applied to last dimension.

https://pytorch.org/docs/stable/torch.html?highlight=norm#torch.norm