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?
JavaScript
x
11
11
1
mu, sigma = 8, 0.5 # mean and standard deviation
2
3
def KHead(nx, ny, mu, sigma):
4
KH0=np.zeros((nx,ny))
5
N=1000
6
for k in range(1,ny-1):
7
for i in range(0,nx-1):
8
KH0[(i,k)]= np.random.normal(mu, sigma, N )
9
10
return KH0
11
Advertisement
Answer
Edited for border of zeros
np.random.normal
takes a size
keyword argument.
You can use it like this:
JavaScript
1
3
1
KH0 = np.zeros((nx, ny))
2
KH0[1:-1,1:-1] = np.random.normal(mu, sigma, (nx -2, ny - 2))
3