title: How to set certain True elements to False in a boolean array in python?
body: <p>I have two boolean arrays <code>a</code> and <code>b</code>. The number of <code>True</code> elements in <code>a</code> is equal to the length of the array <code>b</code>, like this:</p>
  <pre><code>import numpy as np
  a = np.array([0, 1, 0, 1, 0, 0, 0, 1], dtype='bool')
  b = np.array([1,1,0], dtype='bool')
  </code></pre>
  <p>I know that I can use <code>np.where(a)[0]</code> to find the indices of <code>True</code> elements in <code>a</code>:</p>
  <pre><code>idx = np.where(a)[0]
  </code></pre>
  <p>And I have <code>idx</code>:</p>
  <pre><code>array([1, 3, 7])
  </code></pre>
  <p>Now according to <code>b</code></p>
  <pre><code>array([1, 1, 0])
  </code></pre>
  <p>I want to keep the first two <code>True</code> values in <code>a</code> to be <code>True</code>, and flip the last <code>True</code> value to <code>False</code>. That is to say, to flip the value of <code>a[7]</code> to <code>0</code> and keep the rest of values in <code>a</code>:</p>
  <pre><code>res = np.array([0, 1, 0, 1, 0, 0, 0, 0])
  </code></pre>
  <p>How to do it in a python way? Suppose I have a long array of <code>a</code> and a relative short <code>b</code>. The <code>False</code> values in <code>b</code> are not necessarily to be the last one, could happen anywhere and multiple times, so <code>b</code> could also be</p>
  <pre><code>b = np.array([0,1,0], dtype='bool')
  </code></pre>