I need to make a NxN matrix and specify diagonal elements. This is what I tried so far, I was hoping to find a more elegant solution without loops.
N = 4
value_offdiag = 2
b = np.eye(N, N)
b[np.triu_indices(N, 1)] = value_offdiag
b[np.tril_indices(4, -1)] = value_offdiag
This works, but there's got to be a better way without using a loop. Just wanted to check (google search so far hasn't revealed much)