title: Selecting image region based on boolean image mask values
body: <p>I have a rgb image, for example</p>
  
  <pre><code>img_rgb[:,:,0] = [ 125 160; 130 125];
  img_rgb[:,:,1] = [ 125 160; 130 125];
  img_rgb[:,:,2] = [ 125 160; 130 125];
  </code></pre>
  
  <p>and a mask boolean image whose size equals the size of img_rgb e.g</p>
  
  <pre><code>mask[:,:] = [ 1 0; 0 1]
  </code></pre>
  
  <p>for every zero value of mask, I would like to associate a nan value in the img-rgb, thus obtaining the following</p>
  
  <pre><code>img_rgb[:,:,0] = [ 125 nan; nan 125]
  img_rgb[:,:,1] = [ 125 nan; nan 125]
  img_rgb[:,:,2] = [ 125 nan; nan 125]
  </code></pre>
  
  <p>Since my image array is really big (length size 10000px) I would like to do that as fast as possible and thus avoiding a double for cycle. In Matlab I would use the logical operator</p>
  
  <pre><code>img_rgb(repmat(mask,1,1,3)==0)=nan;
  </code></pre>
  
  <p>how can I do something similar in python? python v.2.7
  Thanks in advance</p>