python列表用copy方法复制修改复制列表原列表却也发生了变动,哪里出了问题?
python
m, n = 10, 10
world = 0 for in range(0, m) for in range(0, n)
world01, world12, world20, wo
import numpy as np
m,n = 5,5
world = np.zeros((m,n))
world[0][1], world[1][2], world[2][0], world[2][1], world[2][2] = 1, 1, 1, 1, 1
for day in range(1):
_world = world.copy()
print("_world的值为:\n",_world)
for i in range(0, m):
for j in range(0, n):
state = 0
if not (i == 0 or j == 0):
state += world[i - 1][j - 1]
if not i == 0:
state += world[i - 1][j]
if not (i == 0 or j == n - 1):
state += world[i - 1][j + 1]
if not j == 0:
state += world[i][j - 1]
if not j == n - 1:
state += world[i][j + 1]
if not (i == m - 1 or j == 0):
state += world[i + 1][j - 1]
if not i == m - 1:
state += world[i + 1][j]
if not (i == m - 1 or j == n - 1):
state += world[i + 1][j + 1]
if state < 2 or state > 3:
_world[i][j] = 0
elif state == 3:
_world[i][j] = 1
print("world的值为:\n",world)
world = _world.copy()
print("将_world拷贝后world的值为:\n",world)