In [2]:
import matplotlib.pyplot as plt
import numpy as np

In [12]:
d = np.arange(16)

In [13]:
d4d = d.reshape((2,2,2,2))

In [15]:
d4d.shape


Out[15]:
(2, 2, 2, 2)

In [50]:
d4d[:,:,:,0]


Out[50]:
array([[[ 0,  2],
        [ 4,  6]],

       [[ 8, 10],
        [12, 14]]])

In [58]:
d4d[:,:,:,1]


Out[58]:
array([[[ 1,  3],
        [ 5,  7]],

       [[ 9, 11],
        [13, 15]]])

In [44]:
mask = np.array([True] * 8)

In [51]:
mask


Out[51]:
array([ True, False, False, False, False,  True,  True,  True], dtype=bool)

In [46]:
mask[1:5] = False

In [55]:
mask3d= mask.reshape((2,2,2))

In [66]:
mask3d


Out[66]:
array([[[ True, False],
        [False, False]],

       [[False,  True],
        [ True,  True]]], dtype=bool)

In [67]:
masked = d4d[mask3d,:]

In [71]:
masked.shape


Out[71]:
(4, 2)

In [72]:
masked[:,0]


Out[72]:
array([ 0, 10, 12, 14])

In [73]:
masked[:,1]


Out[73]:
array([ 1, 11, 13, 15])

In [ ]: