とらりもんHOME  Index  Search  Changes  Login

とらりもん - python入門: 遺伝的浮動のシミュレーション Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

# 遺伝的浮動のシミュレーション
import numpy as np
n=100   # number of individuals (population)
timesteps=1000
x=np.zeros(n)
x[0:np.int(n/2)]=1
p=[x.mean()]
for i in range(timesteps):
     x=x[np.random.randint(0, n, n)]
     p+=[x.mean()]
import matplotlib.pyplot as plt
plt.plot(p)
plt.show()