<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="a = torch.rand(3, 3)

a.norm(dim = 1)
#TypeError: norm received an invalid combination of arguments - got (dim=int, ), but expected one of:
# * no arguments
# * (float p)
#      didn't match because some of the keywords were incorrect: dim
# * (float p, int dim)
# * (float p, int dim, bool keepdim)


torch.norm(a, dim = 1)
#TypeError: torch.norm received an invalid combination of arguments - got (torch.FloatTensor, dim=int), but expected one of:
# * (torch.FloatTensor source)
# * (torch.FloatTensor source, float p)
#      didn't match because some of the keywords were incorrect: dim
# * (torch.FloatTensor source, float p, int dim)
# * (torch.FloatTensor source, float p, int dim, bool keepdim)

torch.norm(a, p = 2, dim = 1) # works
a.norm(p = 2, dim = 1) # works
a.norm() # works"><pre class="notranslate"><span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">rand</span>(<span class="pl-c1">3</span>, <span class="pl-c1">3</span>)

<span class="pl-s1">a</span>.<span class="pl-en">norm</span>(<span class="pl-s1">dim</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>)
<span class="pl-c">#TypeError: norm received an invalid combination of arguments - got (dim=int, ), but expected one of:</span>
<span class="pl-c"># * no arguments</span>
<span class="pl-c"># * (float p)</span>
<span class="pl-c">#      didn't match because some of the keywords were incorrect: dim</span>
<span class="pl-c"># * (float p, int dim)</span>
<span class="pl-c"># * (float p, int dim, bool keepdim)</span>


<span class="pl-s1">torch</span>.<span class="pl-en">norm</span>(<span class="pl-s1">a</span>, <span class="pl-s1">dim</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>)
<span class="pl-c">#TypeError: torch.norm received an invalid combination of arguments - got (torch.FloatTensor, dim=int), but expected one of:</span>
<span class="pl-c"># * (torch.FloatTensor source)</span>
<span class="pl-c"># * (torch.FloatTensor source, float p)</span>
<span class="pl-c">#      didn't match because some of the keywords were incorrect: dim</span>
<span class="pl-c"># * (torch.FloatTensor source, float p, int dim)</span>
<span class="pl-c"># * (torch.FloatTensor source, float p, int dim, bool keepdim)</span>

<span class="pl-s1">torch</span>.<span class="pl-en">norm</span>(<span class="pl-s1">a</span>, <span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span>, <span class="pl-s1">dim</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>) <span class="pl-c"># works</span>
<span class="pl-s1">a</span>.<span class="pl-en">norm</span>(<span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span>, <span class="pl-s1">dim</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>) <span class="pl-c"># works</span>
<span class="pl-s1">a</span>.<span class="pl-en">norm</span>() <span class="pl-c"># works</span></pre></div>
<p dir="auto">torch.norm only accepts <code class="notranslate">p, dim</code>, giving only <code class="notranslate">dim</code> results in error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [3]: torch.autograd.Variable(torch.randn(4,8)).norm(dim=1)
Out[3]:
Variable containing:
 2.1210
 3.0991
 2.4054
 2.1048
[torch.FloatTensor of size 4x1]

In [4]: torch.randn(4,8).norm(dim=1)

TypeError: norm received an invalid combination of arguments - got (dim=int, ), but expected one of:
 * no arguments
 * (float p)
      didn't match because some of the keywords were incorrect: dim
 * (float p, int dim)

In [8]: torch.randn(4,8).norm(p=2, dim=1)
Out[8]:

 1.9636
 2.1119
 2.8933
 4.0552
[torch.FloatTensor of size 4x1]"><pre class="notranslate"><code class="notranslate">In [3]: torch.autograd.Variable(torch.randn(4,8)).norm(dim=1)
Out[3]:
Variable containing:
 2.1210
 3.0991
 2.4054
 2.1048
[torch.FloatTensor of size 4x1]

In [4]: torch.randn(4,8).norm(dim=1)

TypeError: norm received an invalid combination of arguments - got (dim=int, ), but expected one of:
 * no arguments
 * (float p)
      didn't match because some of the keywords were incorrect: dim
 * (float p, int dim)

In [8]: torch.randn(4,8).norm(p=2, dim=1)
Out[8]:

 1.9636
 2.1119
 2.8933
 4.0552
[torch.FloatTensor of size 4x1]
</code></pre></div>