Skip to content

Instantly share code, notes, and snippets.

@jetnew
Created October 26, 2021 05:01
Show Gist options
  • Save jetnew/12c01c911751c329f4895fe8df5f94f4 to your computer and use it in GitHub Desktop.
Save jetnew/12c01c911751c329f4895fe8df5f94f4 to your computer and use it in GitHub Desktop.
Game of life with scipy convolution
import numpy as np
from scipy.ndimage import convolve
dim = 10
board = np.zeros((dim, dim), dtype=np.uint8)
kernel = np.array([[1,1,1],
[1,0,1],
[1,1,1]], dtype=np.uint8)
def step(board, kernel=kernel):
convolved = convolve(board, kernel, mode="wrap")
return (((board == 1) & (convolved > 1) & (convolved < 4))
| ((board == 0) & (convolved == 3))).astype(np.uint8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment