title: Python / Numpy: Triangle mask from point mask
body: <p>I'm working with a triangulated mesh consisting of points 3 x n and triangles specified by the point indices 3 x m. I can easily plot that e.g. using mlab</p>
  
  <p><code>mesh = mlab.triangular_mesh(p[0,:],p[1,:],p[2,:],t.T</code></p>
  
  <p>I am also generating a mask masking points which are out of bounds or <code>nan</code>, so I have a mask the size of n. Now I want to mask the triangles which have a masked point. My solutions so far:</p>
  
  <p><strong>1: Use the mask to turn all masked points into <code>nan</code>, e.g.</strong></p>
  
  <pre><code>p[mask] = nan
  </code></pre>
  
  <p><code>mlab</code> then still shows <code>nan</code> (I would need to include a threshold filter...) and I actually don't want to mess with my data</p>
  
  <p><strong>2: Generating a triangle mask, which I started like this</strong></p>
  
  <pre><code>def triangleMask(triangles, pointmask):
      maskedTris = np.zeros((triangles.shape[1]), dtype=np.bool)
      maskedIdx = np.nonzero(pointmask)[0]
      for i,t in enumerate(triangles.T):
           if (i%5000) == 0:
               print('working it.:', i)
           for p in t:
               if p in maskedIdx:
                   maskedTris[i] = True
                   break
  
      return maskedTris
  </code></pre>
  
  <p>This works, but is not fast. And in my case, n = 250.000 and m = 500.000, so "not fast" is quite a problem.</p>
  
  <p>I know there's a mask keyword in <code>mlab</code>, but I cant get it to work. Masking only the points in the triangular_mesh call yields and error since t then refers to indices which are larger than the size of p.</p>