Python 在大矩阵中添加小矩阵
Python add small matrix inside big one
或矩阵,我想将“map”二维数组放入“cmap”中,它大了+2,实际上我想使用“cmap”作为“map”的框架,但我想不使用一个数组(也是因为我想随机生成“地图”二维数组中的字符...您有什么建议吗?
rows, cols = (9, 9)
crows, ccols = (rows + 2, cols + 2)
print(crows, ccols)
cmap = [["#" for x in range(crows)] for y in range(ccols)]
map = [["#" for x in range(rows)] for y in range(cols)]
角色和地图 - 看起来你可能正在制作游戏!
尝试:
border = 1
for i in range(border,len(cmap)-border):
cmap[i][border:-border] = map[i-border]
或矩阵,我想将“map”二维数组放入“cmap”中,它大了+2,实际上我想使用“cmap”作为“map”的框架,但我想不使用一个数组(也是因为我想随机生成“地图”二维数组中的字符...您有什么建议吗?
rows, cols = (9, 9)
crows, ccols = (rows + 2, cols + 2)
print(crows, ccols)
cmap = [["#" for x in range(crows)] for y in range(ccols)]
map = [["#" for x in range(rows)] for y in range(cols)]
角色和地图 - 看起来你可能正在制作游戏!
尝试:
border = 1
for i in range(border,len(cmap)-border):
cmap[i][border:-border] = map[i-border]