Skip to content

Instantly share code, notes, and snippets.

@RNDcpp RNDcpp/life.py
Last active Oct 10, 2019

Embed
What would you like to do?
ライフゲーム
import numpy as np
# 初期値の定義
x=[
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,1,0,0,0],
[0,0,0,1,1,1,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
]
H = len(x)
W = len(x[0])
x = np.array(x).flatten()
N = len(x)
print N
A=[[ 1 if (abs((i/W)-(j/W)) <= 1 and abs((i%W) - (j%W)) <= 1) else 0 for j in range(N)] for i in range(N) ]
A=np.array(A)
b = 1000
T = 20
y=[None]*T # 結果を格納する配列
# シミュレーション
def f(x,y): # ライフゲーム関数
return (np.tanh(b*(2.5-x))*np.tanh(b*(x-3.5-y))+1)/2
for t in range(T):
y[t] = x
x = f(A.dot(x), x)
# 結果をプロットする
for t,j in enumerate(y):
for i in np.array_split(j, H):
print(np.array(i).round().astype(int))
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.