title: Numpy array loss of dimension when masking
body: <p>I want to select certain elements of an array and perform a weighted average calculation based on the values. However, using a filter condition, destroys the original structure of the array. <code>arr</code> which was of shape <code>(2, 2, 3, 2)</code> is turned into a 1-dimensional array. This is of no use to me, as not all these elements need to be combined later on with each other (but subarrays of them). How can I avoid this flattening?</p>
  
  <pre><code>&gt;&gt;&gt; arr = np.asarray([ [[[1, 11], [2, 22], [3, 33]], [[4, 44], [5, 55], [6, 66]]], [ [[7, 77], [8, 88], [9, 99]], [[0, 32], [1, 33], [2, 34] ]] ])
  &gt;&gt;&gt; arr
  array([[[[ 1, 11],
           [ 2, 22],
           [ 3, 33]],
  
          [[ 4, 44],
           [ 5, 55],
           [ 6, 66]]],
  
  
         [[[ 7, 77],
           [ 8, 88],
           [ 9, 99]],
  
          [[ 0, 32],
           [ 1, 33],
           [ 2, 34]]]])
  &gt;&gt;&gt; arr.shape
  (2, 2, 3, 2)
  &gt;&gt;&gt; arr[arr&gt;3]
  array([11, 22, 33,  4, 44,  5, 55,  6, 66,  7, 77,  8, 88,  9, 99, 32, 33,
         34])
  &gt;&gt;&gt; arr[arr&gt;3].shape
  (18,)
  </code></pre>