Это моё решение.Используйте функцию np.append, чтобы добавить свой лабиринт в 2d-массив:
from random import randrange, shuffle
import numpy as np
w = 10
h = 10
vis = [[0] * w + [1] for _ in range(h)] + [[1] * (w + 1)]
ver = [["| "] * w + ['|'] for v in range(h)] + [[]]
hor = [["+--"] * w + ['+'] for v in range(h + 1)]
def go(x, y):
vis[y][x] = 1
d = [(x - 1, y), (x, y + 1), (x + 1, y), (x, y - 1)]
shuffle(d)
for (xx, yy) in d:
if vis[yy][xx]: continue
if xx == x: hor[max(y, yy)][x] = "+ "
if yy == y: ver[y][max(x, xx)] = " "
go(xx, yy)
go(randrange(w), randrange(h))
s = ""
twoD_matrix = np.append([hor[0]], [ver[0]], axis=0)
for i in range(1, len(hor)):
twoD_matrix = np.append(twoD_matrix, [hor[i], ver[1]], axis = 0)
print(twoD_matrix)
Или, если вы предпочитаете список списков, вы можете сделать это следующим образом:
from random import randrange, shuffle
import numpy as np
w = 10
h = 10
vis = [[0] * w + [1] for _ in range(h)] + [[1] * (w + 1)]
ver = [["| "] * w + ['|'] for v in range(h)] + [[]]
hor = [["+--"] * w + ['+'] for v in range(h + 1)]
def go(x, y):
vis[y][x] = 1
d = [(x - 1, y), (x, y + 1), (x + 1, y), (x, y - 1)]
shuffle(d)
for (xx, yy) in d:
if vis[yy][xx]: continue
if xx == x: hor[max(y, yy)][x] = "+ "
if yy == y: ver[y][max(x, xx)] = " "
go(xx, yy)
go(randrange(w), randrange(h))
s = ""
twoD_list = []
for i in range(len(hor)):
twoD_list.append(hor[i])
twoD_list.append(ver[i])
print(twoD_list)