Это не рекурсивно, просто использует встроенные itertools, которые все еще могут быть полезны для вас ... если я правильно понял ваш вопрос, то есть :) В противном случае поправьте меня
import numpy as np
import itertools as it
def other_fun(*args):
return sum(args)
def sample_fun(mtx, *args):
for ids in it.product(*[range(len(obj)) for obj in args]):
mtx[ids] = other_fun(*[obj[idx] for obj,idx in zip(args,ids)])
return mtx
obj1 = [1,2,3]
obj2 = [4,5,6,7]
obj3 = [8,9]
objects = [obj1, obj2, obj3]
mtx = np.zeros([len(obj) for obj in objects])
mtx = sample_fun(mtx, *objects)
print(mtx)