title: How to create a Boolean array from an array of indices in numpy?
body: <p>Given I have an multidimensional array of indices, how do I create a Boolean array from these? For the 1D case it would look like this:</p>
  
  <pre><code>a = [1,5,6]
  b = somefunction(total_array_length=10, a)
  &gt;&gt;&gt; [False, True, False, False, False, True, True, False, False, False]
  </code></pre>
  
  <p>For the 2D case it would look like this:</p>
  
  <pre><code>a = [[1,3],[4,2]]
  b = somefunction(total_array_length=5, a)
  &gt;&gt;&gt; [[False, True, False, True, False], [False, False, True, False, True]]
  </code></pre>
  
  <p>I want to use this to create a mask for an array. I have a multi dimensional array of dimension 8 and for the last axis I can find the indices of the elements I want to keep. In other words, I have an 8D array in which the last axis consists all indices I want to keep in the original array. Does anyone know how to do this?</p>
  
  <p>In the function above the <code>total_array_length</code> would be equal to the length of the original array.</p>
  
  <p>So how would I do this for an array of shape (23,5,76,32,1,3,8,9) with indices array of shape (23,5,76,32,1,3,8,4)? Note 4&lt;9 but other than that it has the same dimensions. </p>
  
  <pre><code>a.shape = (23,5,76,32,1,3,8,4) 
  b = somefunction(total_array_length=9, a)
  b.shape =(23,5,76,32,1,3,8,9) 
  </code></pre>