I created a 2D list and applied a mask on the 2D list followed the same type question. It turned out the posted solution simply didn't work for 2D list. Here is the code and output:
from itertools import compress
class MaskableList(list):
def __getitem__(self, index):
try: return super(MaskableList, self).__getitem__(index)
except TypeError: return MaskableList(compress(self, index))
aa=[['t', 'v'], ['a', 'b']]
aa=MaskableList(aa)
print(aa)
>>> [['t', 'v'], ['a', 'b']]
mask1=[[1,0],[0,1]]
print(aa[mask1])
>>> [['t', 'v'], ['a', 'b']]
mask2=[1,0,0,1]
print(aa[mask2])
>>> [['t', 'v']]
It there a clean and efficient way which works for masking 2D list.