I work with two 3D arrays, which the second arr changes according to the first arr.
I try to turn double for loop into a recursive function, but the same error is repeated, RecursionErroe: maximum recursion depth exceeded in comparison.
The for loops i'm trying to convert:
def to_rec(arr):
new = arr.copy()
row_max = len(arr)
col_max = len(arr[0])
for i in range(row_max):
for j in range(col_max):
new[i, j, :] = 255- arr[i, j, :]
return new
RECURSIVE
def rec2(img, row_max, col_max, i, j, new):
if j == col_mac:
return new
else:
new[i, j, :] = 255 - img[i, j, :]
return rec2(img, row_max, col_max, i, j+1, new)
****************************************************
def rec1(img, row_max, col_max, i, j, new):
if i == row_max:
return new
else:
rec2(img, row_max, col_max, i, j, new)
return rec1(img, row_max, col_max, i+1, 0, new)
********************************************************
def to_rec(arr):
......
# The same data as in to_rac func with the for loop
......
new = rec1(arr, row_max, col_max, 0, 0, new)
return new
I can't figure out what is wrong