I want to set alternating off-diagonal elements in an arbitrary NxN matrix as depicted in the figure.
Currently I use a brute force way, which doesn’t adapt to a change of matrix size:
import numpy as np
dim = 8
size=dim**2
v=0.1
w=1
h = np.zeros(size)
valuesv = [1,8,19,26,37,44,55,62]
valuesw = [10,17,28,35,46,53]
h[valuesv] = v
h[valuesw] = w
ham=h.reshape((int(np.sqrt(size)),int(np.sqrt(size))))
Is there a more elegant way to fill the matrix? E.g. using fill_diagonal of numpy?