title: Calling function on valid values of masked arrays
body: <p>I have two numpy masked arrays:</p>
  
  <pre><code>&gt;&gt;&gt; x
  masked_array(data = [1 2 -- 4],
               mask = [False False  True False],
         fill_value = 999999)
  &gt;&gt;&gt; y
  masked_array(data = [4 -- 0 4],
               mask = [False  True False False],
         fill_value = 999999)
  </code></pre>
  
  <p>If I try to divide <code>x</code> by <code>y</code>, the division operation is not actually performed when one of the operands is masked, so I don't get a divide-by-zero error.</p>
  
  <pre><code>&gt;&gt;&gt; x/y
  masked_array(data = [0.25 -- -- 1.0],
               mask = [False  True  True False],
         fill_value = 1e+20)
  </code></pre>
  
  <p>This even works if I define my own division function, <code>div</code>:</p>
  
  <pre><code>&gt;&gt;&gt; def div(a,b):
      return a/b
  
  &gt;&gt;&gt; div(x, y)
  masked_array(data = [0.25 -- -- 1.0],
               mask = [False  True  True False],
         fill_value = 1e+20)
  </code></pre>
  
  <p>However, if I wrap my function with <code>vectorize</code>, the function is called on masked values and I get an error:</p>
  
  <pre><code>&gt;&gt;&gt; np.vectorize(div)(x, y)
  Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
    File "/usr/lib64/python3.4/site-packages/numpy/lib/function_base.py", line 1811, in __call__
      return self._vectorize_call(func=func, args=vargs)
    File "/usr/lib64/python3.4/site-packages/numpy/lib/function_base.py", line 1880, in _vectorize_call
      outputs = ufunc(*inputs)
    File "&lt;input&gt;", line 2, in div
  ZeroDivisionError: division by zero
  </code></pre>
  
  <p>Is there a way I can call a function with array arguments, and have the function only be executed when all of the arguments are unmasked?</p>