I need to create matrices that follow a specific format: the matrix is a square NxN matrix and the off-diagonals all have the same value (
param) and the diagonals have values such that the rows sum to zero (in other words, they are equal to
0 - param * (N-1). The output is a numpy array
Here is my code. Is there any way I can make this more readable/elegant? Speed is also important.
import numpy as np def makeMatrix(param, N): ar =  for i in range(N): ar.append([ param for st in range(N) ]) ar[i][i] = 0-(param*(N-1)) return np.array(ar, dtype=np.double)