<p dir="auto">Having stacked versions of all possible linear algebra functions would be nice, lstsq being one in particular.</p>
<p dir="auto">See also <a href="http://stackoverflow.com/questions/30442377" rel="nofollow">http://stackoverflow.com/questions/30442377</a> regarding a workaround using svd.</p>
<p dir="auto">See also <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="12995550" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/3217" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/3217/hovercard" href="https://github.com/numpy/numpy/issues/3217">#3217</a>.</p>
<p dir="auto">Many <code class="notranslate">linalg</code> functions are already broadcastable, <code class="notranslate">lstsq</code> isn't.</p>
<p dir="auto">A workaround is via <code class="notranslate">svd</code> which is already broadcasted:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="u, s, v = numpy.linalg.svd(A, full_matrices=False)
uTb = numpy.einsum('ijk,ij-&gt;ik', u, b)
xx = numpy.einsum('ijk, ij-&gt;ik', v, uTb / s)"><pre class="notranslate"><span class="pl-s1">u</span>, <span class="pl-s1">s</span>, <span class="pl-s1">v</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-s1">linalg</span>.<span class="pl-en">svd</span>(<span class="pl-v">A</span>, <span class="pl-s1">full_matrices</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-s1">uTb</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-en">einsum</span>(<span class="pl-s">'ijk,ij-&gt;ik'</span>, <span class="pl-s1">u</span>, <span class="pl-s1">b</span>)
<span class="pl-s1">xx</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-en">einsum</span>(<span class="pl-s">'ijk, ij-&gt;ik'</span>, <span class="pl-s1">v</span>, <span class="pl-s1">uTb</span> <span class="pl-c1">/</span> <span class="pl-s1">s</span>)</pre></div>