title: remove value of numpy array while keeping the dimensions
body: <p>I've a <code>numpy</code> array as follow:</p>
  
  <pre><code>a = np.array([[1, 2, 3, -999.],
                [2, 3, 4, -999.],
                [3, 4, 5, 6]])
  </code></pre>
  
  <p>How can I remove the value <code>-999.</code> while keeping the dimensions, as such:</p>
  
  <pre><code>array([[   1.,    2.,    3.],
         [   2.,    3.,    4.],
         [   3.,    4.,    5.,    6.]])
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>np.delete(a, np.where(a == -999.))
  </code></pre>
  
  <p>But this result in </p>
  
  <pre><code>array([   3.,    2.,    3.,    4., -999.,    3.,    4.,    5.,    6.])
  </code></pre>
  
  <p>And I tried</p>
  
  <pre><code>a[a == -999.] = np.nan
  a[~np.isnan(a)]
  </code></pre>
  
  <p>While it removes the <code>nan</code> (and so the <code>-999</code>), the <code>numpy</code> array becomes <code>1D</code>:</p>
  
  <pre><code>array([1., 2., 3., 2., 3., 4., 3., 4., 5., 6.])
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I use the resulting jagged array (list of lists) for slicing another array where each slice can have a different length.</p>
  
  <p>My use-case:</p>
  
  <pre><code>a = np.random.randint(1,35,size=(100000,5))
  a[a == 14] = -999 # set a missing value
  </code></pre>
  
  <p>Option 1, select values non equal fill value</p>
  
  <pre><code>%%timeit
  slices = np.array([i[i != -999] for i in a])
  
  10 loops, best of 3: 183 ms per loop
  </code></pre>
  
  <p>Option 2, mask and compress</p>
  
  <pre><code>%%timeit
  a_ma = np.ma.masked_equal(a, -999)
  slices = np.array([i.compressed() for i in a_ma])
  
  1 loop, best of 3: 2.99 s per loop
  </code></pre>