【发布时间】:2016-01-29 13:51:39
【问题描述】:
我正在编写代码来模仿康威的生命游戏(10 细胞系)。我快完成了,但我的代码给了我错误
could not broadcast array from shape (7,11) into shape (10)
这是我认为问题所在的代码。
glider = np.zeros([7,11])
glider[3,:]=1
glider[(3,0)]=0
glider[(3,10)]=0
N=(10) # the domain is NxN, N=10 for testing, more interesting with N=100
init_choice = 1 # 0 for random initialization
c = np.random.choice( (1,0), N*N, p=[0.3,0.7] ).reshape(N,N) # default initialization is random
if init_choice == 1:
c = c*0
c[3,:] = glider # put glider in top left
if init_choice == 2:
print("not implemented yet")
periodic(c)
给出结果
-----------------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-53-0a8812bfb2f8> in <module>()
4 if init_choice == 1:
5 c = c*0
6 c[3,:] = glider # put glider in top left
7 if init_choice == 2:
8 print("not implemented yet")
ValueError: could not broadcast input array from shape (7,11) into shape (10)
这是screenshot。
【问题讨论】:
标签: arrays python-3.x numpy anaconda