Я хотел бы ускорить свой код. image3 — это кортеж, состоящий из нулей или единиц. Я думаю, что узкое место в функции make_step. Вы знаете, как мне это ускорить?
for w in range(len(image3[1])-1):
if image1[0,w]==0:
start = 0, w
end = len(image2)-1, 0
##### empty matrix that will store the possible moves
m = []
for i in range(len(image3)):
m.append([])
for j in range(len(image3[i])):
m[-1].append(0)
i,j = start
m[i][j] = 1
def make_step(k,m,image3):
for i in range(len(m)):
for j in range(len(m[i])):
if m[i][j] == k:
if i>0 and m[i-1][j] == 0 and image3[i-1][j] == 0: ##### if there is space in Maze (no space no way) and there is space in the path (to avoid that goes back)
m[i-1][j] = k + 1 ####### on top of the square i,j
if j>0 and m[i][j-1] == 0 and image3[i][j-1] == 0:
m[i][j-1] = k + 1 ####### on left of the square i,j
if i<len(m)-1 and m[i+1][j] == 0 and image3[i+1][j] == 0:
m[i+1][j] = k + 1 ####### on bottom of the square i,j
if j<len(m[i])-1 and m[i][j+1] == 0 and image3[i][j+1] == 0:
m[i][j+1] = k + 1 ####### on right of the square i,j
####### continue to perform step till the end point is reached + if there is a cul-de-sac it
k = 0
while m[end[0]][end[1]] == 0 :
if k<600:
k += 1
make_step(k,m, image3)
# make_step(k,m, image3)
print (k)
else:
break
![Ускорьте код Python [closed] TheFAQ.ru](https://thefaq.ru/wp-content/uploads/2023/01/logo-250.png)