I'm looking to recursively get all the possible permutations of a 2d array of arrays in python. For instance, the trivial case of a matrix with 2 rows would be:
test_array = [[1,2,3,4],
[5,6,7]]
recursions = []
for a in test_array[0]:
for b in test_array[1]:
recursions.append([a,b])
which would output:
[[1, 5], [1, 6], [1, 7], [2, 5], [2, 6], [2, 7], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7]]
I would like to do this for an array including arbitrarily many arrays each of arbitrary length. I'm aware of certain packages such as itertools that can do this, but I'd like to be able to do such a task myself to later extend it to a much more interesting problem.
There are many similar questions on here, such as finding permutations of a 1d array, but I've been unable to find a solution for this elsewhere.