title: Create a dictionary of subcubes from larger cube in Python
body: <p>I am examining every contiguous 8 x 8 x 8 cube within a 50 x 50 x 50 cube.  I am trying to create a collection (in this case a dictionary) of the subcubes that contain the same sum and a count of how many subcubes share that same sum.  So in essence, the result would look something like this:</p>
  <p>{key = sum, value = number of cubes that have the same sum}</p>
  <p>{256 : 3, 119 : 2, ...}</p>
  <p>So in this example, there are 3 cubes that sum to 256 and 2 cubes that sum to 119, etc.  Here is the code I have thus far, but it only sums (at least I think it does):</p>
  <pre><code>an_array = np.array([i for i in range(500)])
  cube = np.reshape(an_array, (8, 8, 8))
  
  c_size = 8 # cube size
  sum = 0
  idx = None
  
  for i in range(cube.shape[0] - cs + 2):
       for j in range(cube.shape[1] - cs + 2):
            for k in range(cube.shape[2] - cs + 2):
            cube_sum = np.sum(cube[i:i + cs, j:j + cs, k:k + cs])
            new_list = {cube_sum : ?}
  </code></pre>
  <p>What I am trying to make this do is iterate the cube within cubes, sum all cubes then count the cubes that share the same sum.  Any ideas would be appreciated.</p>