title: Why can't i squeeze a pic in python
body: <p>I tried to squeeze an image using this code:</p>
  
  <pre><code>def squeeze_image(im,factor):
      new_n = im.shape[0]/ factor
      new_m = im.shape[1]/factor
      new_mat = np.zeros((new_n,new_m)) 
      for j in range(new_mat.shape[1]):
          curr_range = range(j*factor,min((j+1)*factor,im.shape[1])) 
          new_mat[:,j] = im[:,curr_range].mean(axis=1) 
      for i in range(new_mat.shape[0]):
          curr_range1 = range(i*factor,min((i+1)*factor,im.shape[0])) 
          new_mat[i,:] = im[curr_range1,:].mean(axis=0)           
      return new_mat    
  </code></pre>
  
  <p>when i try it on an image it tells me:</p>
  
  <p>ValueError: could not broadcast input array from shape (512) into shape (256)</p>
  
  <p>for some reason it only works when i use it only for rows or only for columns,
  like this:</p>
  
  <pre><code>def squeeze_image(im,factor):
      new_n = im.shape[0]/ factor
      new_m = im.shape[1]/factor
      new_mat = np.zeros((new_n,new_m)) 
      for j in range(new_mat.shape[1]):
          curr_range = range(j*factor,min((j+1)*factor,im.shape[1])) 
          new_mat[:,j] = im[:,curr_range].mean(axis=1) 
      return mat
  </code></pre>
  
  <p>how can i make it work on both rows an columns?</p>