title: How to perform SVD reconstruction for a 3D matrix?
body: <p>I understand how to perform SVD reconstruction for the 2D case,</p>
  <pre><code>import numpy as np
  a = np.random.rand(20, 20)
  u, s, vh = np.linalg.svd(a)
  b = u * s @ vh
  assert np.allclose(a, b)
  </code></pre>
  <p>But I do not understand how to perform SVD reconstruction for the 3D case (specifically for a (k,k,n) matrix, where n is the third dimension)</p>
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-131-40a909c464ae&gt; in &lt;module&gt;
        2 a = np.random.rand(20, 20, 40)
        3 u, s, vh = np.linalg.svd(a)
  ----&gt; 4 b = u * s @ vh
        5 assert np.allclose(a, b)
  
  ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)-&gt;(n?,m?) (size 40 is different from 20)
  
  </code></pre>
  <p>Unfortunately, the document <a href="https://numpy.org/doc/stable/reference/generated/numpy.linalg.svd.html" rel="nofollow noreferrer">https://numpy.org/doc/stable/reference/generated/numpy.linalg.svd.html</a> only has examples for the 2D and 4D cases. How would I perform the reconstruction in a 3D case?</p>