I know it is not wise to work with recursive functions, but I think I need one. I have two vectors (arrays: state1, state2) and would like to interpolate in between with a certain step size (array: step). For three dimensions this function works:

However, I will need to use vectors up to dimension 30. Moreover, the first two dimensions are additive and the rest are multiplicative.How could I generalize these nested loops to a flexible recursive function?

Note that this function makes two assumptions about its inputs: that all input lists are of the same length, and that the values in state2 are always greater or equal to the values in state1 for a positive step, and that this solution will not work for negative steps, as that will result in oscillation between positive and negative values in case of multiplication, which would break the while check. Also note that if you were dealing with additive interpolation only, a better way to implement that would be with Python's built-in range() function, i.e. results.append(range(v1, v2, s)) instead of the while loop.