title: Splitting Python MeshGrid Into Cells
body: <p><strong>Problem Statement</strong></p>
  
  <p>Need to split an N-Dimensional MeshGrid into "cubes":</p>
  
  <p>Ex)
  2-D Case:</p>
  
  <p>(-1,1) |(0,1) |(1,1)</p>
  
  <p>(-1,0) |(0,0) |(1,0)</p>
  
  <p>(-1,-1)|(0,-1)|(1,-1)</p>
  
  <p>There will be 4 cells, each with 2^D points:</p>
  
  <p>I want to be able to process the mesh, placing the coordinate points of each cell into a container to do further processing.</p>
  
  <pre><code>Cells =   [{(-1,1) (0,1)(-1,0),(0,0)},
  
            {(0,1),(1,1),(0,0),(1,0)},
  
            {(-1,0),(0,0)(-1,-1),(0,-1)}
  
            {(0,0),(1,0)(0,-1),(1,-1)}]
  </code></pre>
  
  <p>I use the following to generate the mesh for an arbitrary dimension d:</p>
  
  <pre><code>grid = [np.linspace(-1.0 , 1.0, num = K+1) for i in range(d)]
  res_to_unpack = np.meshgrid(*grid,indexing = 'ij')
  </code></pre>
  
  <p>Which has output:</p>
  
  <pre><code>[array([[-1., -1., -1.],
     [ 0.,  0.,  0.],
     [ 1.,  1.,  1.]]), array([[-1.,  0.,  1.],
     [-1.,  0.,  1.],
     [-1.,  0.,  1.]])]
  </code></pre>
  
  <p>So I want to be able to generate the above cells container for a given D dimensional mesh grid. Split on a given K that is a power of 2. </p>
  
  <p>I need this container so for each cell, I need to reference all 2^D points associated and calculate the distance from an origin. </p>
  
  <p><strong>Edit For Clarification</strong></p>
  
  <p>K should partition the grid into K ** D number of cells, with (K+1) ** D points. Each Cell should have 2 ** D number of points. Each "cell" will have volume (2/K)^D. </p>
  
  <p>So for K = 4, D = 2</p>
  
  <pre><code>Cells = [ {(-1,1),(-0.5,1),(-1,0.5),(-0.5,0.5)},
            {(-0.5,1),(-0.5,0.5)(0.0,1.0),(0,0.5)},
              ...
            {(0.0,-0.5),(0.5,-0.5),(0.0,-1.0),(0.5,-1.0)},
            {(0.5,-1.0),(0.5,-1.0),(1.0,-0.5),(1.0,-1.0)}]
  </code></pre>
  
  <p>This is output for TopLeft, TopLeft + Right Over, Bottom Left, Bottom Left + Over Left. There will we 16 cells in this set, each with four coordinates each. For increasing K, say K = 8. There will be 64 cells, each with four points.</p>