I would like to select certain columns and rows from a big 2D array. For example, I want to select N = 64 columns after every D = 128 columns, if my big array were to have shape (384,384), this would result to a smaller (256, 256) matrix, essentially because I want to remove redundant data from the big matrix.
My code looks like below, the problem is that I don't know how to avoid the explicit indexing(here 4 times in each direction, actually can be implemented as a loop with generic size) in a nice way without using loops if possible. Also in this example I start selection from 0 column, in general it can be started from arbitrary column.
row_mask = np.zeros(rows, dtype=bool) # e.g. rows = 384
col_mask = np.zeros(cols, dtype=bool) # e.g. cols = 384
N = 64
D = 128
# explicit selection of columns and rows
row_mask[0:N] = 1
row_mask[D:D + N] = 1
row_mask[D * 2:D * 2 + N] = 1
row_mask[-N:] = 1
col_mask[0:N] = 1
col_mask[D:D + N] = 1
col_mask[D * 2:D * 2 + N] = 1
col_mask[-N:] = 1
#Image of (384, 384), image of (256, 256)
image = Image[np.ix_(row_mask, col_mask)]