title: Mapping elements in 3D lower "triangle" to linear structure
body: <p>This is the 3D version of an existing <a href="https://stackoverflow.com/questions/4803180/mapping-elements-in-2d-upper-triangle-and-lower-triangle-to-linear-structure?lq=1">question</a>.</p>
  
  <p>A 3D array <code>M[x,y,z]</code> of shape <code>(n,n,n)</code> should be mapped to a flat vector containing only the  elements with x&lt;=y&lt;=z in order to save space. So what I need is an expression similar to the 2D case (<a href="https://stackoverflow.com/a/4803504/60982"><code>index := x + (y+1)*y/2</code></a>). I tried to derive some formulas but just can't get it right. Note that the element order inside the vector doesn't matter.</p>