Created
October 26, 2021 05:01
Game of life with scipy convolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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