def get_part(arr, shape, offsets):
    slices = tuple(slice(offs, offs + length) for offs, length in zip(
        offsets, shape))
return arr[slices]
get_part(arr, mask.shape, (3, 4))
How to efficiently set values of numpy array using indices and boolean indexing?