title: A particular way of resizing a matrix
body: <p>Having a <em>nxn</em> (<em>6x6</em> in the example below) matrix filled only with 0 and 1:</p>
  
  <pre><code>old_matrix=[[0,0,0,1,1,0],
              [1,1,1,1,0,0],
              [0,0,1,0,0,0],
              [1,0,0,0,0,1],
              [0,1,1,1,1,0],
              [1,0,0,1,1,0]]
  </code></pre>
  
  <p>I want to resize it in a particular way. Taking <em>(2x2)</em> sub-matrice and checking if there are more ones or zeros. This means the new matrix will be <em>(3x3)</em> If there are more 1 than 0 un the sub-matrice a 1 value will be assigned in the new matrix. Otherwise, (if there are less or equal) its new value will be 0.</p>
  
  <pre><code>new_matrix=[[0,1,0],
              [0,0,0],
              [0,1,0]]
  </code></pre>
  
  <p>I've tried to achieve this by using lots of whiles. However it doesn seem to work. Here's what I got so far: </p>
  
  <pre><code> def convert_track(a):
  
     #converts original map to a 8x8 tile Track
  
     NEW_TRACK=[]
     w=0 #matrix width
     h=0 #matrix heigth
     t_w=0 #submatrix width
     t_h=0 #submatrix heigth
     BLACK=0 #number of ones in submatrix
     WHITE=0 #number of zeros in submatrix
     while h&lt;=6:
         while w&lt;=6:
             l=[]
             while t_h&lt;=2 and h&lt;=6:
                 t_w=0
                 while t_w&lt;=2 and w&lt;=6:
                     if a[h][w]==1:
                         BLACK+=1
                     else:
                         WHITE+=1
                     t_w+=1
                     w+=1
                     h+=1
                     t_h+=1
                 t_w=0
                 t_h+=1
             if BLACK&lt;=WHITE:
                 l.append(0)
             else:
                 l.append(1)
             BLACK=0
             WHITE=0
             t_h=0     
         NEW_TRACK.append(l)
     return NEW_TRACK 
  </code></pre>
  
  <p>Raises the error <em>list index out of range</em> or returns the list</p>
  
  <pre><code>[[0]]
  </code></pre>
  
  <p>is there an easier way to achieve this? What am i doing wrong? </p>