Reputation: 127
I need to create an nxn matrix in which the numbers in the cells are distributed following a Gaussian distribution. This code may not go well because it fills a cell with a sequence. how can I do?
mu, sigma = 8, 0.5 # mean and standard deviation
def KHead(nx, ny, mu, sigma):
KH0=np.zeros((nx,ny))
N=1000
for k in range(1,ny-1):
for i in range(0,nx-1):
KH0[(i,k)]= np.random.normal(mu, sigma, N )
return KH0
Upvotes: 0
Views: 542
Reputation: 2182
Edited for border of zeros
np.random.normal
takes a size
keyword argument.
You can use it like this:
KH0 = np.zeros((nx, ny))
KH0[1:-1,1:-1] = np.random.normal(mu, sigma, (nx -2, ny - 2))
Upvotes: 1