Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- x = np.random.random((10,10))>0.3
- y = x.copy()
- print(y)
- k = 1
- nei = 0
- while k <= 20:
- for i in range(y.shape[0]):
- for j in range(y.shape[1]):
- if i != 0 and j != 0 and i != 9 and j != 9:
- nei += y[i-1,j-1]
- nei += y[i-1,j]
- nei += y[i-1,j+1]
- nei += y[i,j-1]
- nei += y[i,j+1]
- nei += y[i+1,j-1]
- nei += y[i+1,j]
- nei += y[i+1,j+1]
- if y[i,j] == True:
- if (nei < 2) or (nei > 3):
- y[i,j] = False
- else:
- y[i,j] = True
- elif y[i,j] == False:
- if (nei < 2) or (nei >= 4):
- #if nei == 3:
- y[i,j] == False
- else:
- y[i,j] = True
- else:
- pass
- k += 1
- print(y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement