In matrix of sub-matrices, select diagonal indices of off-diagonal submatrices
I'm sure there are other ways, but in the meantime, how about this:

my_matrix = np.tile(np.eye(submatrix_size), (n_submatrix, n_submatrix))
np.fill_diagonal(my_matrix, 0)


Then again, the concatenation of matrixes might not be particularly
efficient, so instead I'd rather compute the target indexes directly,
fill them, and possibly clear out the diagonal again (all destructive on
a previously allocated matrix):

cells = n_submatrix * submatrix_size
my_matrix = np.zeros((cells, cells))

for x in range(n_submatrix):
    for y in range(submatrix_size):
        r = range(y, n_submatrix * submatrix_size, submatrix_size)
        my_matrix[x * submatrix_size + y, r] = 1

np.fill_diagonal(my_matrix, 0)


That is still easily explained:  we step first by number of submatrixes
(because that's where the pattern repeats), then for each row we set all
indexes in that row at once, offset by the current step in the
submatrix.

Again, that seems less efficient than calculating indexes at once.  I
ended up with the following:

cells = n_submatrix * submatrix_size
my_matrix = np.zeros((cells, cells))

for y in range(submatrix_size):
    r = range(y, n_submatrix * submatrix_size, submatrix_size)
    my_matrix[np.ix_(r, r)] = 1

np.fill_diagonal(my_matrix, 0)


To be fair, the documentation for numpy.ix_ and
indexing
isn't particularly intuitive, but basically I was looking for a way to
compress the notion of "for each of these rows, select all the indexes
in that row" and then setting them all at once.  Now there is only one
loop for each row in the submatrix and I'm out of ideas.

There might be a clever formula to generate all of the indexes in one go
(by calculating them modulo some number) for all the diagonals though.



Btw. for your code I'd suggest extracting expressions as variables (like
cells above) and possibly a bit more succinct names, but that's just
me.