title: Getting "ValueError: operands could not be broadcast together with shapes" when trying to subtract from channel wise mean in Caffe
body: <p>This is a follow-up question from <a href="https://stackoverflow.com/questions/45294732/caffes-transformer-preprocessing-takes-too-long-to-complete">this</a>. Basically what I want to do is to simply subtract each image from the mean.</p>
  
  <p>Based on this issue on <a href="https://github.com/BVLC/caffe/issues/1928" rel="nofollow noreferrer">GitHub</a> and <a href="https://groups.google.com/forum/#!topic/caffe-users/JocRGMOCmk0" rel="nofollow noreferrer">this other similar question</a>, and also <a href="https://github.com/BVLC/caffe/blob/master/examples/00-classification.ipynb" rel="nofollow noreferrer">this classification example</a> When we feed the cropped version of images to the network, we need to subtract the mean pixel using something like this:</p>
  
  <pre><code>mu = mean_file.mean(1).mean(1)
  </code></pre>
  
  <p>but the irony is when I want to do this:</p>
  
  <pre><code>.. = (img[:,0:224,0:224] - mu)
  </code></pre>
  
  <p>I get <code>ValueError: operands could not be broadcast together with shapes (3,224,224) (3,)</code>. I'm not well-versed at Python and Numpy and can't figure out what the error message is trying to convey.</p>
  
  <p>Currently, I'm cropping the mean file, which is not ideal, but is better than nothing.</p>
  
  <pre><code>.. = (img[:,0:224,0:224] - mean_image[:,0:224,0:224])
  </code></pre>