Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import numpy as np
  2. x = np.random.random((10,10))>0.3
  3. y = x.copy()
  4. print(y)
  5. k = 1
  6. nei = 0
  7. while k <= 20:
  8.     for i in range(y.shape[0]):
  9.         for j in range(y.shape[1]):
  10.             if i != 0 and j != 0 and i != 9 and j != 9:
  11.                 nei += y[i-1,j-1]
  12.                 nei += y[i-1,j]
  13.                 nei += y[i-1,j+1]
  14.                 nei += y[i,j-1]
  15.                 nei += y[i,j+1]
  16.                 nei += y[i+1,j-1]
  17.                 nei += y[i+1,j]
  18.                 nei += y[i+1,j+1]
  19.                 if y[i,j] == True:
  20.                     if (nei < 2) or (nei > 3):
  21.                         y[i,j] = False
  22.                     else:
  23.                         y[i,j] = True
  24.                 elif y[i,j] == False:
  25.                     if (nei < 2) or (nei >= 4):
  26.                     #if nei == 3:
  27.                         y[i,j] == False
  28.                     else:
  29.                         y[i,j] = True
  30.             else:
  31.                 pass
  32.     k += 1
  33. print(y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement