<p dir="auto">In some cases, it would be really handy to be able to do this:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; a = randn(5, 100);

julia&gt; norm(a, dims=1)  # Doesn't work
ERROR: MethodError: no method matching norm(::Matrix{Float64}; dims=2)

julia&gt; sqrt.(sum(abs2, a, dims=1))  # Intended result (in this case, with `p=2`)
1×100 Matrix{Float64}:
 1.26534  0.763155  2.55044  2.38645  1.69696  …  1.71206  2.61463  2.81637  1.82003  1.69302"><pre class="notranslate">julia<span class="pl-k">&gt;</span> a <span class="pl-k">=</span> <span class="pl-c1">randn</span>(<span class="pl-c1">5</span>, <span class="pl-c1">100</span>);

julia<span class="pl-k">&gt;</span> <span class="pl-c1">norm</span>(a, dims<span class="pl-k">=</span><span class="pl-c1">1</span>)  <span class="pl-c"><span class="pl-c">#</span> Doesn't work</span>
ERROR<span class="pl-k">:</span> MethodError<span class="pl-k">:</span> no method matching <span class="pl-c1">norm</span>(<span class="pl-k">::</span><span class="pl-c1">Matrix{Float64}</span>; dims<span class="pl-k">=</span><span class="pl-c1">2</span>)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">sqrt</span>.(<span class="pl-c1">sum</span>(abs2, a, dims<span class="pl-k">=</span><span class="pl-c1">1</span>))  <span class="pl-c"><span class="pl-c">#</span> Intended result (in this case, with `p=2`)</span>
<span class="pl-c1">1</span><span class="pl-k">×</span><span class="pl-c1">100</span> Matrix{Float64}<span class="pl-k">:</span>
 <span class="pl-c1">1.26534</span>  <span class="pl-c1">0.763155</span>  <span class="pl-c1">2.55044</span>  <span class="pl-c1">2.38645</span>  <span class="pl-c1">1.69696</span>  …  <span class="pl-c1">1.71206</span>  <span class="pl-c1">2.61463</span>  <span class="pl-c1">2.81637</span>  <span class="pl-c1">1.82003</span>  <span class="pl-c1">1.69302</span></pre></div>
<p dir="auto">As a more advanced example, for a tensor <code class="notranslate">a</code> of shape <code class="notranslate">(m, n, k)</code>, <code class="notranslate">norm(a, dims=(2, 3))</code> would compute <code class="notranslate">norm(a[i, :, :])</code> for all <code class="notranslate">i</code> and return something of shape <code class="notranslate">(m, 1, 1)</code>.</p>
<p dir="auto">It would be nice if the <code class="notranslate">LinearAlgebra.norm</code> function have the <code class="notranslate">dims</code> keyword, like others linear algebra functions and like numpy norm axis parameter (<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html" rel="nofollow">https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html</a>)</p>
<p dir="auto">Just for example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function norm(itr, p::Real=2; dims)
    sum(itr.^p; dims=dims).^(1/p)
end"><pre class="notranslate"><code class="notranslate">function norm(itr, p::Real=2; dims)
    sum(itr.^p; dims=dims).^(1/p)
end
</code></pre></div>